Commit 10f9a948 authored by Marshall Greenblatt's avatar Marshall Greenblatt

views: Support ink drop effect on buttons (issue #2102)

parent f8909fe9
......@@ -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.
......
......@@ -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.
......
......@@ -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<CefLabelButton> 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<cef_button_state_t>(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();
......
......@@ -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;
......
......@@ -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<cef_label_button_t*>(
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;
......
......@@ -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<cef_menu_button_t*>(
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;
......
......@@ -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))
......
......@@ -35,6 +35,7 @@ class CefButtonCToCpp
CefRefPtr<CefLabelButton> 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;
......
......@@ -249,6 +249,18 @@ cef_button_state_t CefLabelButtonCToCpp::GetState() {
return _retval;
}
void CefLabelButtonCToCpp::SetInkDropEnabled(bool enabled) {
cef_button_t* _struct = reinterpret_cast<cef_button_t*>(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<cef_button_t*>(GetStruct());
if (CEF_MEMBER_MISSING(_struct, set_tooltip_text))
......
......@@ -50,6 +50,7 @@ class CefLabelButtonCToCpp
CefRefPtr<CefLabelButton> 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;
......
......@@ -294,6 +294,18 @@ cef_button_state_t CefMenuButtonCToCpp::GetState() {
return _retval;
}
void CefMenuButtonCToCpp::SetInkDropEnabled(bool enabled) {
cef_button_t* _struct = reinterpret_cast<cef_button_t*>(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<cef_button_t*>(GetStruct());
if (CEF_MEMBER_MISSING(_struct, set_tooltip_text))
......
......@@ -54,6 +54,7 @@ class CefMenuButtonCToCpp
CefRefPtr<CefLabelButton> 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;
......
......@@ -77,6 +77,7 @@ CefRefPtr<CefMenuModel> ViewsMenuBar::CreateMenuModel(const CefString& label,
CefRefPtr<CefMenuButton> 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.
......
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment