diff --git a/include/capi/views/cef_button_capi.h b/include/capi/views/cef_button_capi.h index 43ccaf1e3..36a0dedf1 100644 --- a/include/capi/views/cef_button_capi.h +++ b/include/capi/views/cef_button_capi.h @@ -74,6 +74,12 @@ typedef struct _cef_button_t { /// cef_button_state_t (CEF_CALLBACK *get_state)(struct _cef_button_t* self); + /// + // Sets the Button will use an ink drop effect for displaying state changes. + /// + void (CEF_CALLBACK *set_ink_drop_enabled)(struct _cef_button_t* self, + int enabled); + /// // Sets the tooltip text that will be displayed when the user hovers the mouse // cursor over the Button. diff --git a/include/views/cef_button.h b/include/views/cef_button.h index 2feda9a63..db3db7d62 100644 --- a/include/views/cef_button.h +++ b/include/views/cef_button.h @@ -68,6 +68,12 @@ class CefButton : public CefView { /*--cef(default_retval=CEF_BUTTON_STATE_NORMAL)--*/ virtual cef_button_state_t GetState() =0; + /// + // Sets the Button will use an ink drop effect for displaying state changes. + /// + /*--cef()--*/ + virtual void SetInkDropEnabled(bool enabled) =0; + /// // Sets the tooltip text that will be displayed when the user hovers the mouse // cursor over the Button. diff --git a/libcef/browser/views/button_impl.h b/libcef/browser/views/button_impl.h index fc9601c7c..8d3518c07 100644 --- a/libcef/browser/views/button_impl.h +++ b/libcef/browser/views/button_impl.h @@ -12,6 +12,7 @@ #include "libcef/browser/views/view_impl.h" #include "base/logging.h" +#include "ui/gfx/color_utils.h" #include "ui/views/controls/button/custom_button.h" // Helpers for template boiler-plate. @@ -30,6 +31,7 @@ CEF_BUTTON_IMPL_T class CefButtonImpl : public CEF_VIEW_IMPL_D { CefRefPtr AsLabelButton() override { return nullptr; } void SetState(cef_button_state_t state) override; cef_button_state_t GetState() override; + void SetInkDropEnabled(bool enabled) override; void SetTooltipText(const CefString& tooltip_text) override; void SetAccessibleName(const CefString& name) override; @@ -57,6 +59,18 @@ CEF_BUTTON_IMPL_T cef_button_state_t CEF_BUTTON_IMPL_D::GetState() { return static_cast(ParentClass::root_view()->state()); } +CEF_BUTTON_IMPL_T void CEF_BUTTON_IMPL_D::SetInkDropEnabled(bool enabled) { + CEF_REQUIRE_VALID_RETURN_VOID(); + ParentClass::root_view()->SetInkDropMode( + enabled ? views::InkDropHostView::InkDropMode::ON : + views::InkDropHostView::InkDropMode::OFF); + if (enabled) { + ParentClass::root_view()->set_ink_drop_base_color( + color_utils::BlendTowardOppositeLuma( + ParentClass::root_view()->background()->get_color(), 0x61)); + } +} + CEF_BUTTON_IMPL_T void CEF_BUTTON_IMPL_D::SetTooltipText( const CefString& tooltip_text) { CEF_REQUIRE_VALID_RETURN_VOID(); diff --git a/libcef_dll/cpptoc/views/button_cpptoc.cc b/libcef_dll/cpptoc/views/button_cpptoc.cc index 08231e712..48f29445f 100644 --- a/libcef_dll/cpptoc/views/button_cpptoc.cc +++ b/libcef_dll/cpptoc/views/button_cpptoc.cc @@ -69,6 +69,19 @@ cef_button_state_t CEF_CALLBACK button_get_state(struct _cef_button_t* self) { return _retval; } +void CEF_CALLBACK button_set_ink_drop_enabled(struct _cef_button_t* self, + int enabled) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + + // Execute + CefButtonCppToC::Get(self)->SetInkDropEnabled( + enabled?true:false); +} + void CEF_CALLBACK button_set_tooltip_text(struct _cef_button_t* self, const cef_string_t* tooltip_text) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -927,6 +940,7 @@ CefButtonCppToC::CefButtonCppToC() { GetStruct()->as_label_button = button_as_label_button; GetStruct()->set_state = button_set_state; GetStruct()->get_state = button_get_state; + GetStruct()->set_ink_drop_enabled = button_set_ink_drop_enabled; GetStruct()->set_tooltip_text = button_set_tooltip_text; GetStruct()->set_accessible_name = button_set_accessible_name; GetStruct()->base.as_browser_view = button_as_browser_view; diff --git a/libcef_dll/cpptoc/views/label_button_cpptoc.cc b/libcef_dll/cpptoc/views/label_button_cpptoc.cc index 589608932..c300a3896 100644 --- a/libcef_dll/cpptoc/views/label_button_cpptoc.cc +++ b/libcef_dll/cpptoc/views/label_button_cpptoc.cc @@ -274,6 +274,20 @@ cef_button_state_t CEF_CALLBACK label_button_get_state( return _retval; } +void CEF_CALLBACK label_button_set_ink_drop_enabled(struct _cef_button_t* self, + int enabled) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + + // Execute + CefLabelButtonCppToC::Get(reinterpret_cast( + self))->SetInkDropEnabled( + enabled?true:false); +} + void CEF_CALLBACK label_button_set_tooltip_text(struct _cef_button_t* self, const cef_string_t* tooltip_text) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -1165,6 +1179,7 @@ CefLabelButtonCppToC::CefLabelButtonCppToC() { GetStruct()->base.as_label_button = label_button_as_label_button; GetStruct()->base.set_state = label_button_set_state; GetStruct()->base.get_state = label_button_get_state; + GetStruct()->base.set_ink_drop_enabled = label_button_set_ink_drop_enabled; GetStruct()->base.set_tooltip_text = label_button_set_tooltip_text; GetStruct()->base.set_accessible_name = label_button_set_accessible_name; GetStruct()->base.base.as_browser_view = label_button_as_browser_view; diff --git a/libcef_dll/cpptoc/views/menu_button_cpptoc.cc b/libcef_dll/cpptoc/views/menu_button_cpptoc.cc index d7e0c17a6..2ab91ffa1 100644 --- a/libcef_dll/cpptoc/views/menu_button_cpptoc.cc +++ b/libcef_dll/cpptoc/views/menu_button_cpptoc.cc @@ -323,6 +323,20 @@ cef_button_state_t CEF_CALLBACK menu_button_get_state( return _retval; } +void CEF_CALLBACK menu_button_set_ink_drop_enabled(struct _cef_button_t* self, + int enabled) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + + // Execute + CefMenuButtonCppToC::Get(reinterpret_cast( + self))->SetInkDropEnabled( + enabled?true:false); +} + void CEF_CALLBACK menu_button_set_tooltip_text(struct _cef_button_t* self, const cef_string_t* tooltip_text) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -1214,6 +1228,8 @@ CefMenuButtonCppToC::CefMenuButtonCppToC() { GetStruct()->base.base.as_label_button = menu_button_as_label_button; GetStruct()->base.base.set_state = menu_button_set_state; GetStruct()->base.base.get_state = menu_button_get_state; + GetStruct()->base.base.set_ink_drop_enabled = + menu_button_set_ink_drop_enabled; GetStruct()->base.base.set_tooltip_text = menu_button_set_tooltip_text; GetStruct()->base.base.set_accessible_name = menu_button_set_accessible_name; GetStruct()->base.base.base.as_browser_view = menu_button_as_browser_view; diff --git a/libcef_dll/ctocpp/views/button_ctocpp.cc b/libcef_dll/ctocpp/views/button_ctocpp.cc index 83bb06c6a..48f3984c6 100644 --- a/libcef_dll/ctocpp/views/button_ctocpp.cc +++ b/libcef_dll/ctocpp/views/button_ctocpp.cc @@ -64,6 +64,18 @@ cef_button_state_t CefButtonCToCpp::GetState() { return _retval; } +void CefButtonCToCpp::SetInkDropEnabled(bool enabled) { + cef_button_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, set_ink_drop_enabled)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + _struct->set_ink_drop_enabled(_struct, + enabled); +} + void CefButtonCToCpp::SetTooltipText(const CefString& tooltip_text) { cef_button_t* _struct = GetStruct(); if (CEF_MEMBER_MISSING(_struct, set_tooltip_text)) diff --git a/libcef_dll/ctocpp/views/button_ctocpp.h b/libcef_dll/ctocpp/views/button_ctocpp.h index e6eff8d94..d3b19644d 100644 --- a/libcef_dll/ctocpp/views/button_ctocpp.h +++ b/libcef_dll/ctocpp/views/button_ctocpp.h @@ -35,6 +35,7 @@ class CefButtonCToCpp CefRefPtr AsLabelButton() OVERRIDE; void SetState(cef_button_state_t state) OVERRIDE; cef_button_state_t GetState() OVERRIDE; + void SetInkDropEnabled(bool enabled) OVERRIDE; void SetTooltipText(const CefString& tooltip_text) OVERRIDE; void SetAccessibleName(const CefString& name) OVERRIDE; diff --git a/libcef_dll/ctocpp/views/label_button_ctocpp.cc b/libcef_dll/ctocpp/views/label_button_ctocpp.cc index ecc052bae..bfad07004 100644 --- a/libcef_dll/ctocpp/views/label_button_ctocpp.cc +++ b/libcef_dll/ctocpp/views/label_button_ctocpp.cc @@ -249,6 +249,18 @@ cef_button_state_t CefLabelButtonCToCpp::GetState() { return _retval; } +void CefLabelButtonCToCpp::SetInkDropEnabled(bool enabled) { + cef_button_t* _struct = reinterpret_cast(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, set_ink_drop_enabled)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + _struct->set_ink_drop_enabled(_struct, + enabled); +} + void CefLabelButtonCToCpp::SetTooltipText(const CefString& tooltip_text) { cef_button_t* _struct = reinterpret_cast(GetStruct()); if (CEF_MEMBER_MISSING(_struct, set_tooltip_text)) diff --git a/libcef_dll/ctocpp/views/label_button_ctocpp.h b/libcef_dll/ctocpp/views/label_button_ctocpp.h index cd78a22fc..ff5c3c874 100644 --- a/libcef_dll/ctocpp/views/label_button_ctocpp.h +++ b/libcef_dll/ctocpp/views/label_button_ctocpp.h @@ -50,6 +50,7 @@ class CefLabelButtonCToCpp CefRefPtr AsLabelButton() OVERRIDE; void SetState(cef_button_state_t state) OVERRIDE; cef_button_state_t GetState() OVERRIDE; + void SetInkDropEnabled(bool enabled) OVERRIDE; void SetTooltipText(const CefString& tooltip_text) OVERRIDE; void SetAccessibleName(const CefString& name) OVERRIDE; diff --git a/libcef_dll/ctocpp/views/menu_button_ctocpp.cc b/libcef_dll/ctocpp/views/menu_button_ctocpp.cc index 009bc6647..406847627 100644 --- a/libcef_dll/ctocpp/views/menu_button_ctocpp.cc +++ b/libcef_dll/ctocpp/views/menu_button_ctocpp.cc @@ -294,6 +294,18 @@ cef_button_state_t CefMenuButtonCToCpp::GetState() { return _retval; } +void CefMenuButtonCToCpp::SetInkDropEnabled(bool enabled) { + cef_button_t* _struct = reinterpret_cast(GetStruct()); + if (CEF_MEMBER_MISSING(_struct, set_ink_drop_enabled)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + _struct->set_ink_drop_enabled(_struct, + enabled); +} + void CefMenuButtonCToCpp::SetTooltipText(const CefString& tooltip_text) { cef_button_t* _struct = reinterpret_cast(GetStruct()); if (CEF_MEMBER_MISSING(_struct, set_tooltip_text)) diff --git a/libcef_dll/ctocpp/views/menu_button_ctocpp.h b/libcef_dll/ctocpp/views/menu_button_ctocpp.h index b4342ed8d..045de2ba3 100644 --- a/libcef_dll/ctocpp/views/menu_button_ctocpp.h +++ b/libcef_dll/ctocpp/views/menu_button_ctocpp.h @@ -54,6 +54,7 @@ class CefMenuButtonCToCpp CefRefPtr AsLabelButton() OVERRIDE; void SetState(cef_button_state_t state) OVERRIDE; cef_button_state_t GetState() OVERRIDE; + void SetInkDropEnabled(bool enabled) OVERRIDE; void SetTooltipText(const CefString& tooltip_text) OVERRIDE; void SetAccessibleName(const CefString& name) OVERRIDE; diff --git a/tests/cefclient/browser/views_menu_bar.cc b/tests/cefclient/browser/views_menu_bar.cc index 23fadc1a6..20b4937a6 100644 --- a/tests/cefclient/browser/views_menu_bar.cc +++ b/tests/cefclient/browser/views_menu_bar.cc @@ -77,6 +77,7 @@ CefRefPtr ViewsMenuBar::CreateMenuModel(const CefString& label, CefRefPtr button = CefMenuButton::CreateMenuButton(this, label, false, false); button->SetID(new_menu_id); + button->SetInkDropEnabled(true); // Assign a group ID to allow focus traversal between MenuButtons using the // arrow keys when the menu is not displayed. diff --git a/tests/cefclient/browser/views_window.cc b/tests/cefclient/browser/views_window.cc index 6ef7e482c..cfdf06129 100644 --- a/tests/cefclient/browser/views_window.cc +++ b/tests/cefclient/browser/views_window.cc @@ -569,6 +569,7 @@ void ViewsWindow::AddControls() { CefMenuButton::CreateMenuButton(this, CefString(), false, false); menu_button->SetID(ID_MENU_BUTTON); menu_button->SetImage(CEF_BUTTON_STATE_NORMAL, LoadImageIcon("menu_icon")); + menu_button->SetInkDropEnabled(true); // Override the default minimum size. menu_button->SetMinimumSize(CefSize(0, 0));