2017-02-22 19:05:27 +01:00
|
|
|
diff --git ui/base/models/menu_model.h ui/base/models/menu_model.h
|
2020-06-09 19:48:00 +02:00
|
|
|
index 887eee64e27f..31d4d453a481 100644
|
2017-02-22 19:05:27 +01:00
|
|
|
--- ui/base/models/menu_model.h
|
|
|
|
+++ ui/base/models/menu_model.h
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -12,8 +12,11 @@
|
|
|
|
#include "ui/base/ui_base_export.h"
|
|
|
|
#include "ui/gfx/native_widget_types.h"
|
|
|
|
|
|
|
|
+#include "third_party/skia/include/core/SkColor.h"
|
|
|
|
+
|
2017-02-22 19:05:27 +01:00
|
|
|
namespace gfx {
|
|
|
|
class FontList;
|
|
|
|
+class Point;
|
|
|
|
}
|
|
|
|
|
2020-06-09 19:48:00 +02:00
|
|
|
namespace ui {
|
|
|
|
@@ -119,6 +122,27 @@ class UI_BASE_EXPORT MenuModel : public base::SupportsWeakPtr<MenuModel> {
|
2017-02-22 19:05:27 +01:00
|
|
|
// |event_flags| is a bit mask of ui::EventFlags.
|
|
|
|
virtual void ActivatedAt(int index, int event_flags);
|
|
|
|
|
|
|
|
+ // Called when the user moves the mouse outside the menu and over the owning
|
|
|
|
+ // window.
|
|
|
|
+ virtual void MouseOutsideMenu(const gfx::Point& screen_point) {}
|
|
|
|
+
|
|
|
|
+ // Called on unhandled open/close submenu keyboard commands. |is_rtl| will be
|
|
|
|
+ // true if the menu is displaying a right-to-left language.
|
|
|
|
+ virtual void UnhandledOpenSubmenu(bool is_rtl) {}
|
|
|
|
+ virtual void UnhandledCloseSubmenu(bool is_rtl) {}
|
2017-02-25 06:03:31 +01:00
|
|
|
+
|
|
|
|
+ // Override the text/background color of a given menu item dependent on the
|
2017-03-03 23:37:23 +01:00
|
|
|
+ // |index| and its |is_hovered| state. |is_minor| will be true for accelerator
|
|
|
|
+ // text. Returns true if it chooses to override the color.
|
2017-02-25 06:03:31 +01:00
|
|
|
+ virtual bool GetTextColor(int index,
|
2017-03-03 23:37:23 +01:00
|
|
|
+ bool is_minor,
|
2017-02-25 06:03:31 +01:00
|
|
|
+ bool is_hovered,
|
|
|
|
+ SkColor* override_color) const { return false; }
|
|
|
|
+ virtual bool GetBackgroundColor(int index,
|
|
|
|
+ bool is_hovered,
|
|
|
|
+ SkColor* override_color) const
|
|
|
|
+ { return false; }
|
2017-02-22 19:05:27 +01:00
|
|
|
+
|
|
|
|
// Called when the menu is about to be shown.
|
|
|
|
virtual void MenuWillShow() {}
|
|
|
|
|
2017-02-24 21:01:42 +01:00
|
|
|
diff --git ui/gfx/render_text.cc ui/gfx/render_text.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
index ddbad437878c..4e86541fb68b 100644
|
2017-02-24 21:01:42 +01:00
|
|
|
--- ui/gfx/render_text.cc
|
|
|
|
+++ ui/gfx/render_text.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -610,6 +610,14 @@ void RenderText::SetWhitespaceElision(base::Optional<bool> whitespace_elision) {
|
2017-02-24 21:01:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+void RenderText::SetDrawStringsFlags(int flags) {
|
|
|
|
+ if (draw_strings_flags_ == flags)
|
|
|
|
+ return;
|
|
|
|
+ draw_strings_flags_ = flags;
|
|
|
|
+ cached_bounds_and_offset_valid_ = false;
|
|
|
|
+ OnTextAttributeChanged();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void RenderText::SetDisplayRect(const Rect& r) {
|
|
|
|
if (r != display_rect_) {
|
|
|
|
display_rect_ = r;
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -1990,6 +1998,19 @@ void RenderText::OnTextAttributeChanged() {
|
2020-02-10 18:10:17 +01:00
|
|
|
|
|
|
|
layout_text_up_to_date_ = false;
|
2017-02-24 21:01:42 +01:00
|
|
|
|
|
|
|
+ if (draw_strings_flags_ != 0) {
|
|
|
|
+ // Compute layout size with the mnemonic character underlined since it might
|
|
|
|
+ // be larger than with the underline hidden.
|
|
|
|
+ int char_pos = -1;
|
|
|
|
+ int char_span = 0;
|
|
|
|
+ layout_text_ =
|
|
|
|
+ gfx::RemoveAcceleratorChar(layout_text_, '&', &char_pos, &char_span);
|
|
|
|
+ if (char_pos != -1) {
|
|
|
|
+ gfx::Range range(char_pos, char_pos + char_span);
|
2019-02-01 20:40:18 +01:00
|
|
|
+ styles_[TEXT_STYLE_UNDERLINE].ApplyValue(true, range);
|
2017-02-24 21:01:42 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
OnLayoutTextAttributeChanged(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git ui/gfx/render_text.h ui/gfx/render_text.h
|
2020-06-09 19:48:00 +02:00
|
|
|
index 8cfbd5c5c4af..80a6c8a8674c 100644
|
2017-02-24 21:01:42 +01:00
|
|
|
--- ui/gfx/render_text.h
|
|
|
|
+++ ui/gfx/render_text.h
|
2020-03-04 01:29:39 +01:00
|
|
|
@@ -324,6 +324,10 @@ class GFX_EXPORT RenderText {
|
2019-09-04 17:13:32 +02:00
|
|
|
return whitespace_elision_;
|
|
|
|
}
|
2017-02-24 21:01:42 +01:00
|
|
|
|
|
|
|
+ // Get or set the flags that control display of accelerator characters.
|
|
|
|
+ void SetDrawStringsFlags(int flags);
|
|
|
|
+ int draw_strings_flags() const { return draw_strings_flags_; }
|
|
|
|
+
|
|
|
|
const Rect& display_rect() const { return display_rect_; }
|
|
|
|
void SetDisplayRect(const Rect& r);
|
|
|
|
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -1015,6 +1019,8 @@ class GFX_EXPORT RenderText {
|
2020-03-04 01:29:39 +01:00
|
|
|
// Tell whether or not the |layout_text_| needs an update or is up to date.
|
|
|
|
mutable bool layout_text_up_to_date_ = false;
|
2017-02-24 21:01:42 +01:00
|
|
|
|
|
|
|
+ int draw_strings_flags_ = 0;
|
|
|
|
+
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RenderText);
|
|
|
|
};
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
diff --git ui/views/animation/ink_drop_host_view.h ui/views/animation/ink_drop_host_view.h
|
2020-03-30 22:13:42 +02:00
|
|
|
index b711c5f08f80..d0d428057e5d 100644
|
2017-05-31 17:33:30 +02:00
|
|
|
--- ui/views/animation/ink_drop_host_view.h
|
|
|
|
+++ ui/views/animation/ink_drop_host_view.h
|
2020-03-30 22:13:42 +02:00
|
|
|
@@ -138,6 +138,8 @@ class VIEWS_EXPORT InkDropHostView : public View {
|
2020-03-04 01:29:39 +01:00
|
|
|
// this isn't necessary anymore.
|
|
|
|
virtual InkDrop* GetInkDrop();
|
2017-05-31 17:33:30 +02:00
|
|
|
|
|
|
|
+ InkDropMode ink_drop_mode() const { return ink_drop_mode_; }
|
|
|
|
+
|
2017-08-04 00:55:19 +02:00
|
|
|
protected:
|
2018-05-14 13:24:05 +02:00
|
|
|
// Size used for the default SquareInkDropRipple.
|
2019-11-12 17:11:44 +01:00
|
|
|
static constexpr gfx::Size kDefaultInkDropSize = gfx::Size(24, 24);
|
2017-02-24 21:01:42 +01:00
|
|
|
diff --git ui/views/controls/button/label_button.cc ui/views/controls/button/label_button.cc
|
2020-04-14 21:31:00 +02:00
|
|
|
index bb9105f1a18e..45ae9cdb4ab0 100644
|
2017-02-24 21:01:42 +01:00
|
|
|
--- ui/views/controls/button/label_button.cc
|
|
|
|
+++ ui/views/controls/button/label_button.cc
|
2020-04-14 21:31:00 +02:00
|
|
|
@@ -480,6 +480,12 @@ void LabelButton::OnThemeChanged() {
|
2019-07-16 19:59:21 +02:00
|
|
|
SchedulePaint();
|
2017-05-31 17:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+void LabelButton::SetFontList(const gfx::FontList& font_list) {
|
|
|
|
+ cached_normal_font_list_ = font_list;
|
2017-08-08 22:10:24 +02:00
|
|
|
+ cached_default_button_font_list_ = font_list;
|
2017-05-31 17:33:30 +02:00
|
|
|
+ label_->SetFontList(cached_normal_font_list_);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void LabelButton::StateChanged(ButtonState old_state) {
|
|
|
|
const gfx::Size previous_image_size(image_->GetPreferredSize());
|
|
|
|
UpdateImage();
|
|
|
|
diff --git ui/views/controls/button/label_button.h ui/views/controls/button/label_button.h
|
2020-03-30 22:13:42 +02:00
|
|
|
index ac348aa7dd46..88ab098daddc 100644
|
2017-05-31 17:33:30 +02:00
|
|
|
--- ui/views/controls/button/label_button.h
|
|
|
|
+++ ui/views/controls/button/label_button.h
|
2020-03-30 22:13:42 +02:00
|
|
|
@@ -124,6 +124,9 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
|
2019-07-16 19:59:21 +02:00
|
|
|
ui::NativeTheme::State GetForegroundThemeState(
|
|
|
|
ui::NativeTheme::ExtraParams* params) const override;
|
2017-05-31 17:33:30 +02:00
|
|
|
|
|
|
|
+ // Sets the font list used by this button.
|
|
|
|
+ void SetFontList(const gfx::FontList& font_list);
|
|
|
|
+
|
|
|
|
protected:
|
|
|
|
ImageView* image() const { return image_; }
|
2019-07-16 19:59:21 +02:00
|
|
|
Label* label() const { return label_; }
|
2017-02-23 21:24:45 +01:00
|
|
|
diff --git ui/views/controls/label.cc ui/views/controls/label.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
index ad6af149e286..bef8ab77d961 100644
|
2017-02-23 21:24:45 +01:00
|
|
|
--- ui/views/controls/label.cc
|
|
|
|
+++ ui/views/controls/label.cc
|
2019-11-12 17:11:44 +01:00
|
|
|
@@ -53,6 +53,20 @@ bool IsOpaque(SkColor color) {
|
2019-09-04 17:13:32 +02:00
|
|
|
return SkColorGetA(color) == SK_AlphaOPAQUE;
|
|
|
|
}
|
2019-01-17 10:56:52 +01:00
|
|
|
|
2017-02-23 21:24:45 +01:00
|
|
|
+// Strips accelerator character prefixes in |text| if needed, based on |flags|.
|
|
|
|
+// Returns a range in |text| to underline or Range::InvalidRange() if
|
|
|
|
+// underlining is not needed.
|
|
|
|
+gfx::Range StripAcceleratorChars(int flags, base::string16* text) {
|
|
|
|
+ if (flags & (gfx::Canvas::SHOW_PREFIX | gfx::Canvas::HIDE_PREFIX)) {
|
|
|
|
+ int char_pos = -1;
|
|
|
|
+ int char_span = 0;
|
|
|
|
+ *text = gfx::RemoveAcceleratorChar(*text, '&', &char_pos, &char_span);
|
|
|
|
+ if ((flags & gfx::Canvas::SHOW_PREFIX) && char_pos != -1)
|
|
|
|
+ return gfx::Range(char_pos, char_pos + char_span);
|
|
|
|
+ }
|
2019-09-04 17:13:32 +02:00
|
|
|
+ return gfx::Range::InvalidRange();
|
2017-02-23 21:24:45 +01:00
|
|
|
+}
|
2019-01-17 10:56:52 +01:00
|
|
|
+
|
2019-09-04 17:13:32 +02:00
|
|
|
} // namespace
|
2019-01-17 10:56:52 +01:00
|
|
|
|
2019-09-04 17:13:32 +02:00
|
|
|
namespace views {
|
2020-04-14 21:31:00 +02:00
|
|
|
@@ -308,6 +322,14 @@ base::string16 Label::GetTooltipText() const {
|
2019-09-04 17:13:32 +02:00
|
|
|
return tooltip_text_;
|
2017-02-23 21:24:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+void Label::SetDrawStringsFlags(int flags) {
|
|
|
|
+ if (draw_strings_flags_ == flags)
|
|
|
|
+ return;
|
|
|
|
+ draw_strings_flags_ = flags;
|
2018-02-15 01:12:09 +01:00
|
|
|
+ full_text_->SetDrawStringsFlags(draw_strings_flags_);
|
2017-02-23 21:24:45 +01:00
|
|
|
+ ResetLayout();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void Label::SetTooltipText(const base::string16& tooltip_text) {
|
|
|
|
DCHECK(handles_tooltips_);
|
2019-09-04 17:13:32 +02:00
|
|
|
if (tooltip_text_ == tooltip_text)
|
2020-04-14 21:31:00 +02:00
|
|
|
@@ -582,7 +604,19 @@ std::unique_ptr<gfx::RenderText> Label::CreateRenderText() const {
|
2017-02-23 21:24:45 +01:00
|
|
|
render_text->SetFontList(font_list());
|
2019-10-01 15:55:16 +02:00
|
|
|
render_text->set_shadows(GetShadows());
|
2017-02-23 21:24:45 +01:00
|
|
|
render_text->SetCursorEnabled(false);
|
2019-09-04 17:13:32 +02:00
|
|
|
- render_text->SetText(GetText());
|
2017-02-23 21:24:45 +01:00
|
|
|
+
|
|
|
|
+ if (draw_strings_flags_ != 0) {
|
2019-09-04 17:13:32 +02:00
|
|
|
+ base::string16 text_str = GetText();
|
2017-02-23 21:24:45 +01:00
|
|
|
+ gfx::Range range = StripAcceleratorChars(draw_strings_flags_, &text_str);
|
|
|
|
+ render_text->SetText(text_str);
|
|
|
|
+ if (range.IsValid()) {
|
|
|
|
+ render_text->SetDisplayRect(bounds());
|
2019-02-01 20:40:18 +01:00
|
|
|
+ render_text->ApplyStyle(gfx::TEXT_STYLE_UNDERLINE, true, range);
|
2017-02-23 21:24:45 +01:00
|
|
|
+ }
|
|
|
|
+ } else {
|
2019-09-04 17:13:32 +02:00
|
|
|
+ render_text->SetText(GetText());
|
2017-02-23 21:24:45 +01:00
|
|
|
+ }
|
|
|
|
+
|
2019-10-01 15:55:16 +02:00
|
|
|
const bool multiline = GetMultiLine();
|
|
|
|
render_text->SetMultiline(multiline);
|
|
|
|
render_text->SetMaxLines(multiline ? GetMaxLines() : 0);
|
2017-02-23 21:24:45 +01:00
|
|
|
diff --git ui/views/controls/label.h ui/views/controls/label.h
|
2020-06-09 19:48:00 +02:00
|
|
|
index dc690b22dc25..d07d1df9aa2f 100644
|
2017-02-23 21:24:45 +01:00
|
|
|
--- ui/views/controls/label.h
|
|
|
|
+++ ui/views/controls/label.h
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -183,6 +183,10 @@ class VIEWS_EXPORT Label : public View,
|
2019-09-04 17:13:32 +02:00
|
|
|
gfx::ElideBehavior GetElideBehavior() const;
|
2017-02-23 21:24:45 +01:00
|
|
|
void SetElideBehavior(gfx::ElideBehavior elide_behavior);
|
|
|
|
|
|
|
|
+ // Get or set the flags that control display of accelerator characters.
|
|
|
|
+ void SetDrawStringsFlags(int flags);
|
2019-09-04 17:13:32 +02:00
|
|
|
+ int GetDrawStringsFlags() const { return draw_strings_flags_; }
|
2017-02-23 21:24:45 +01:00
|
|
|
+
|
2019-09-04 17:13:32 +02:00
|
|
|
// Gets/Sets the tooltip text. Default behavior for a label (single-line) is
|
|
|
|
// to show the full text if it is wider than its bounds. Calling this
|
|
|
|
// overrides the default behavior and lets you set a custom tooltip. To
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -416,6 +420,7 @@ class VIEWS_EXPORT Label : public View,
|
2020-03-30 22:13:42 +02:00
|
|
|
bool collapse_when_hidden_ = false;
|
|
|
|
int fixed_width_ = 0;
|
|
|
|
int max_width_ = 0;
|
2017-02-23 21:24:45 +01:00
|
|
|
+ int draw_strings_flags_ = 0;
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
std::unique_ptr<SelectionController> selection_controller_;
|
|
|
|
|
2017-02-22 19:05:27 +01:00
|
|
|
diff --git ui/views/controls/menu/menu_controller.cc ui/views/controls/menu/menu_controller.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
index d9938916a535..bc7eaa23c9c6 100644
|
2017-02-22 19:05:27 +01:00
|
|
|
--- ui/views/controls/menu/menu_controller.cc
|
|
|
|
+++ ui/views/controls/menu/menu_controller.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -2651,8 +2651,13 @@ MenuItemView* MenuController::FindNextSelectableMenuItem(
|
2017-02-22 19:05:27 +01:00
|
|
|
|
|
|
|
void MenuController::OpenSubmenuChangeSelectionIfCan() {
|
|
|
|
MenuItemView* item = pending_state_.item;
|
2019-07-16 19:59:21 +02:00
|
|
|
- if (!item->HasSubmenu() || !item->GetEnabled())
|
|
|
|
+ if (!item->HasSubmenu() || !item->GetEnabled() || !item->GetParentMenuItem()) {
|
2017-02-22 19:05:27 +01:00
|
|
|
+ MenuItemView* submenu_item =
|
|
|
|
+ item->GetParentMenuItem() ? item->GetParentMenuItem() : item;
|
|
|
|
+ submenu_item->GetDelegate()->OnUnhandledOpenSubmenu(submenu_item,
|
|
|
|
+ base::i18n::IsRTL());
|
|
|
|
return;
|
|
|
|
+ }
|
2019-04-16 16:38:48 +02:00
|
|
|
MenuItemView* to_select = nullptr;
|
2019-06-05 16:15:45 +02:00
|
|
|
if (!item->GetSubmenu()->GetMenuItems().empty())
|
2017-02-22 19:05:27 +01:00
|
|
|
to_select = FindInitialSelectableMenuItem(item, INCREMENT_SELECTION_DOWN);
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -2671,8 +2676,10 @@ void MenuController::OpenSubmenuChangeSelectionIfCan() {
|
2017-02-22 19:05:27 +01:00
|
|
|
void MenuController::CloseSubmenu() {
|
|
|
|
MenuItemView* item = state_.item;
|
|
|
|
DCHECK(item);
|
|
|
|
- if (!item->GetParentMenuItem())
|
|
|
|
+ if (!item->GetParentMenuItem()) {
|
|
|
|
+ item->GetDelegate()->OnUnhandledCloseSubmenu(item, base::i18n::IsRTL());
|
|
|
|
return;
|
|
|
|
+ }
|
2017-07-27 01:19:27 +02:00
|
|
|
if (item->SubmenuIsShowing())
|
2017-02-22 19:05:27 +01:00
|
|
|
SetSelection(item, SELECTION_UPDATE_IMMEDIATELY);
|
|
|
|
else if (item->GetParentMenuItem()->GetParentMenuItem())
|
|
|
|
diff --git ui/views/controls/menu/menu_delegate.h ui/views/controls/menu/menu_delegate.h
|
2020-03-30 22:13:42 +02:00
|
|
|
index 2a03ff43f4a6..c12d68eb212c 100644
|
2017-02-22 19:05:27 +01:00
|
|
|
--- ui/views/controls/menu/menu_delegate.h
|
|
|
|
+++ ui/views/controls/menu/menu_delegate.h
|
2018-11-30 23:21:07 +01:00
|
|
|
@@ -81,6 +81,22 @@ class VIEWS_EXPORT MenuDelegate {
|
2018-09-04 11:43:21 +02:00
|
|
|
// parts of |style| or leave it unmodified.
|
|
|
|
virtual void GetLabelStyle(int id, LabelStyle* style) const;
|
2017-05-31 17:33:30 +02:00
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
+ // Override the text color of a given menu item dependent on the |command_id|
|
|
|
|
+ // and its |is_hovered| state. |is_minor| will be true for accelerator text.
|
|
|
|
+ // Returns true if it chooses to override the color.
|
|
|
|
+ virtual bool GetTextColor(int command_id,
|
|
|
|
+ bool is_minor,
|
|
|
|
+ bool is_hovered,
|
|
|
|
+ SkColor* override_color) const { return false; }
|
|
|
|
+
|
|
|
|
+ // Override the background color of a given menu item dependent on the
|
2017-02-25 06:03:31 +01:00
|
|
|
+ // |command_id| and its |is_hovered| state. Returns true if it chooses to
|
|
|
|
+ // override the color.
|
2017-03-03 23:37:23 +01:00
|
|
|
+ virtual bool GetBackgroundColor(int command_id,
|
|
|
|
+ bool is_hovered,
|
|
|
|
+ SkColor* override_color) const
|
|
|
|
+ { return false; }
|
2017-05-31 17:33:30 +02:00
|
|
|
+
|
2017-03-03 23:37:23 +01:00
|
|
|
// The tooltip shown for the menu item. This is invoked when the user
|
|
|
|
// hovers over the item, and no tooltip text has been set for that item.
|
2017-05-31 17:33:30 +02:00
|
|
|
virtual base::string16 GetTooltipText(int id,
|
2020-03-30 22:13:42 +02:00
|
|
|
@@ -207,6 +223,11 @@ class VIEWS_EXPORT MenuDelegate {
|
2017-02-22 19:05:27 +01:00
|
|
|
bool* has_mnemonics,
|
|
|
|
MenuButton** button);
|
|
|
|
|
|
|
|
+ // Called on unhandled open/close submenu keyboard commands. |is_rtl| will be
|
|
|
|
+ // true if the menu is displaying a right-to-left language.
|
|
|
|
+ virtual void OnUnhandledOpenSubmenu(MenuItemView* menu, bool is_rtl) {}
|
|
|
|
+ virtual void OnUnhandledCloseSubmenu(MenuItemView* menu, bool is_rtl) {}
|
|
|
|
+
|
|
|
|
// Returns the max width menus can grow to be.
|
|
|
|
virtual int GetMaxWidthForMenu(MenuItemView* menu);
|
|
|
|
|
2017-02-25 06:03:31 +01:00
|
|
|
diff --git ui/views/controls/menu/menu_item_view.cc ui/views/controls/menu/menu_item_view.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
index d00618f37c3a..3157ba4f219b 100644
|
2017-02-25 06:03:31 +01:00
|
|
|
--- ui/views/controls/menu/menu_item_view.cc
|
|
|
|
+++ ui/views/controls/menu/menu_item_view.cc
|
2020-04-14 21:31:00 +02:00
|
|
|
@@ -987,6 +987,15 @@ void MenuItemView::PaintBackground(gfx::Canvas* canvas,
|
2018-11-30 23:21:07 +01:00
|
|
|
spilling_rect.set_y(spilling_rect.y() - corner_radius_);
|
|
|
|
spilling_rect.set_height(spilling_rect.height() + corner_radius_);
|
|
|
|
canvas->DrawRoundRect(spilling_rect, corner_radius_, flags);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ MenuDelegate *delegate = GetDelegate();
|
2017-03-03 23:37:23 +01:00
|
|
|
+ SkColor override_color;
|
|
|
|
+ if (delegate && delegate->GetBackgroundColor(GetCommand(),
|
|
|
|
+ render_selection,
|
|
|
|
+ &override_color)) {
|
|
|
|
+ canvas->DrawColor(override_color);
|
2018-11-30 23:21:07 +01:00
|
|
|
} else if (render_selection) {
|
|
|
|
gfx::Rect item_bounds = GetLocalBounds();
|
2020-03-04 01:29:39 +01:00
|
|
|
if (type_ == Type::kActionableSubMenu) {
|
2020-04-14 21:31:00 +02:00
|
|
|
@@ -1054,6 +1063,13 @@ void MenuItemView::PaintMinorIconAndText(
|
2018-09-04 11:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SkColor MenuItemView::GetTextColor(bool minor, bool render_selection) const {
|
2017-02-25 06:03:31 +01:00
|
|
|
+ SkColor text_color;
|
2017-03-03 23:37:23 +01:00
|
|
|
+ const MenuDelegate *delegate = GetDelegate();
|
|
|
|
+ if (delegate && delegate->GetTextColor(GetCommand(), minor, render_selection,
|
|
|
|
+ &text_color)) {
|
|
|
|
+ return text_color;
|
2017-02-25 06:03:31 +01:00
|
|
|
+ }
|
|
|
|
+
|
2019-11-12 17:11:44 +01:00
|
|
|
style::TextContext context =
|
|
|
|
GetMenuController() && GetMenuController()->use_touchable_layout()
|
|
|
|
? style::CONTEXT_TOUCH_MENU
|
2017-02-22 19:05:27 +01:00
|
|
|
diff --git ui/views/controls/menu/menu_model_adapter.cc ui/views/controls/menu/menu_model_adapter.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
index 79af9195b11f..a30375d1a6ed 100644
|
2017-02-22 19:05:27 +01:00
|
|
|
--- ui/views/controls/menu/menu_model_adapter.cc
|
|
|
|
+++ ui/views/controls/menu/menu_model_adapter.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -233,6 +233,77 @@ bool MenuModelAdapter::IsItemChecked(int id) const {
|
2019-02-01 17:42:40 +01:00
|
|
|
return false;
|
2017-02-22 19:05:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+MenuItemView* MenuModelAdapter::GetSiblingMenu(MenuItemView* menu,
|
|
|
|
+ const gfx::Point& screen_point,
|
|
|
|
+ MenuAnchorPosition* anchor,
|
|
|
|
+ bool* has_mnemonics,
|
|
|
|
+ MenuButton** button) {
|
|
|
|
+ // Look up the menu model for this menu.
|
|
|
|
+ const std::map<MenuItemView*, ui::MenuModel*>::const_iterator map_iterator =
|
|
|
|
+ menu_map_.find(menu);
|
|
|
|
+ if (map_iterator != menu_map_.end()) {
|
|
|
|
+ map_iterator->second->MouseOutsideMenu(screen_point);
|
|
|
|
+ return nullptr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ NOTREACHED();
|
|
|
|
+ return nullptr;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MenuModelAdapter::OnUnhandledOpenSubmenu(MenuItemView* menu,
|
|
|
|
+ bool is_rtl) {
|
|
|
|
+ // Look up the menu model for this menu.
|
|
|
|
+ const std::map<MenuItemView*, ui::MenuModel*>::const_iterator map_iterator =
|
|
|
|
+ menu_map_.find(menu);
|
|
|
|
+ if (map_iterator != menu_map_.end()) {
|
|
|
|
+ map_iterator->second->UnhandledOpenSubmenu(is_rtl);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ NOTREACHED();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void MenuModelAdapter::OnUnhandledCloseSubmenu(MenuItemView* menu,
|
|
|
|
+ bool is_rtl) {
|
|
|
|
+ // Look up the menu model for this menu.
|
|
|
|
+ const std::map<MenuItemView*, ui::MenuModel*>::const_iterator map_iterator =
|
|
|
|
+ menu_map_.find(menu);
|
|
|
|
+ if (map_iterator != menu_map_.end()) {
|
|
|
|
+ map_iterator->second->UnhandledCloseSubmenu(is_rtl);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ NOTREACHED();
|
|
|
|
+}
|
2017-02-25 06:03:31 +01:00
|
|
|
+
|
2017-03-03 23:37:23 +01:00
|
|
|
+bool MenuModelAdapter::GetTextColor(int command_id,
|
|
|
|
+ bool is_minor,
|
|
|
|
+ bool is_hovered,
|
|
|
|
+ SkColor* override_color) const {
|
2017-02-25 06:03:31 +01:00
|
|
|
+ ui::MenuModel* model = menu_model_;
|
|
|
|
+ int index = 0;
|
|
|
|
+ if (ui::MenuModel::GetModelAndIndexForCommandId(command_id, &model, &index))
|
2017-03-03 23:37:23 +01:00
|
|
|
+ return model->GetTextColor(index, is_minor, is_hovered, override_color);
|
2017-02-25 06:03:31 +01:00
|
|
|
+
|
|
|
|
+ NOTREACHED();
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool MenuModelAdapter::GetBackgroundColor(int command_id,
|
|
|
|
+ bool is_hovered,
|
|
|
|
+ SkColor* override_color) const {
|
|
|
|
+ if (command_id == -1)
|
|
|
|
+ return menu_model_->GetBackgroundColor(-1, is_hovered, override_color);
|
|
|
|
+
|
|
|
|
+ ui::MenuModel* model = menu_model_;
|
|
|
|
+ int index = 0;
|
|
|
|
+ if (ui::MenuModel::GetModelAndIndexForCommandId(command_id, &model, &index))
|
|
|
|
+ return model->GetBackgroundColor(index, is_hovered, override_color);
|
|
|
|
+
|
|
|
|
+ NOTREACHED();
|
|
|
|
+ return false;
|
|
|
|
+}
|
2017-02-22 19:05:27 +01:00
|
|
|
+
|
|
|
|
void MenuModelAdapter::WillShowMenu(MenuItemView* menu) {
|
|
|
|
// Look up the menu model for this menu.
|
|
|
|
const std::map<MenuItemView*, ui::MenuModel*>::const_iterator map_iterator =
|
|
|
|
diff --git ui/views/controls/menu/menu_model_adapter.h ui/views/controls/menu/menu_model_adapter.h
|
2019-06-05 16:15:45 +02:00
|
|
|
index 78f832fd3acf..cb030c991614 100644
|
2017-02-22 19:05:27 +01:00
|
|
|
--- ui/views/controls/menu/menu_model_adapter.h
|
|
|
|
+++ ui/views/controls/menu/menu_model_adapter.h
|
2019-02-21 01:42:36 +01:00
|
|
|
@@ -84,6 +84,20 @@ class VIEWS_EXPORT MenuModelAdapter : public MenuDelegate,
|
2019-02-01 17:42:40 +01:00
|
|
|
bool IsCommandEnabled(int id) const override;
|
2017-02-22 19:05:27 +01:00
|
|
|
bool IsCommandVisible(int id) const override;
|
|
|
|
bool IsItemChecked(int id) const override;
|
|
|
|
+ MenuItemView* GetSiblingMenu(MenuItemView* menu,
|
|
|
|
+ const gfx::Point& screen_point,
|
|
|
|
+ MenuAnchorPosition* anchor,
|
|
|
|
+ bool* has_mnemonics,
|
|
|
|
+ MenuButton** button) override;
|
|
|
|
+ void OnUnhandledOpenSubmenu(MenuItemView* menu, bool is_rtl) override;
|
|
|
|
+ void OnUnhandledCloseSubmenu(MenuItemView* menu, bool is_rtl) override;
|
2017-03-03 23:37:23 +01:00
|
|
|
+ bool GetTextColor(int command_id,
|
|
|
|
+ bool is_minor,
|
|
|
|
+ bool is_hovered,
|
|
|
|
+ SkColor* override_color) const override;
|
2017-02-25 06:03:31 +01:00
|
|
|
+ bool GetBackgroundColor(int command_id,
|
|
|
|
+ bool is_hovered,
|
|
|
|
+ SkColor* override_color) const override;
|
2017-02-22 19:05:27 +01:00
|
|
|
void WillShowMenu(MenuItemView* menu) override;
|
|
|
|
void WillHideMenu(MenuItemView* menu) override;
|
2017-05-31 17:33:30 +02:00
|
|
|
void OnMenuClosed(MenuItemView* menu) override;
|
2017-02-25 06:03:31 +01:00
|
|
|
diff --git ui/views/controls/menu/menu_scroll_view_container.cc ui/views/controls/menu/menu_scroll_view_container.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
index 3ba6950690e3..f500022cc083 100644
|
2017-02-25 06:03:31 +01:00
|
|
|
--- ui/views/controls/menu/menu_scroll_view_container.cc
|
|
|
|
+++ ui/views/controls/menu/menu_scroll_view_container.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -199,6 +199,11 @@ MenuScrollViewContainer::MenuScrollViewContainer(SubmenuView* content_view)
|
2019-11-12 17:11:44 +01:00
|
|
|
scroll_down_button_ =
|
|
|
|
AddChildView(std::make_unique<MenuScrollButton>(content_view, false));
|
2017-02-25 06:03:31 +01:00
|
|
|
|
|
|
|
+ SkColor override_color;
|
|
|
|
+ MenuDelegate* delegate = content_view_->GetMenuItem()->GetDelegate();
|
|
|
|
+ if (delegate && delegate->GetBackgroundColor(-1, false, &override_color))
|
2017-07-27 01:19:27 +02:00
|
|
|
+ SetBackground(views::CreateSolidBackground(override_color));
|
2017-02-25 06:03:31 +01:00
|
|
|
+
|
|
|
|
arrow_ = BubbleBorderTypeFromAnchor(
|
|
|
|
content_view_->GetMenuItem()->GetMenuController()->GetAnchorPosition());
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
diff --git ui/views/test/ui_controls_factory_desktop_aurax11.cc ui/views/test/ui_controls_factory_desktop_aurax11.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
index 0ba3742be89f..6187478ecfc7 100644
|
2017-05-31 17:33:30 +02:00
|
|
|
--- ui/views/test/ui_controls_factory_desktop_aurax11.cc
|
|
|
|
+++ ui/views/test/ui_controls_factory_desktop_aurax11.cc
|
2020-06-09 19:48:00 +02:00
|
|
|
@@ -150,10 +150,6 @@ class UIControlsDesktopX11 : public UIControlsAura {
|
2017-05-31 17:33:30 +02:00
|
|
|
aura::test::QueryLatestMousePositionRequestInHost(host);
|
|
|
|
host->ConvertPixelsToDIP(&root_current_location);
|
|
|
|
|
|
|
|
- auto* screen = views::test::TestDesktopScreenX11::GetInstance();
|
|
|
|
- DCHECK_EQ(screen, display::Screen::GetScreen());
|
|
|
|
- screen->set_cursor_screen_point(gfx::Point(screen_x, screen_y));
|
|
|
|
-
|
|
|
|
if (root_location != root_current_location && button_down_mask == 0) {
|
|
|
|
// Move the cursor because EnterNotify/LeaveNotify are generated with the
|
|
|
|
// current mouse position as a result of XGrabPointer()
|
|
|
|
diff --git ui/views/view.h ui/views/view.h
|
2020-06-09 19:48:00 +02:00
|
|
|
index 1f4f1eb78fe2..15bda55cb8f9 100644
|
2017-05-31 17:33:30 +02:00
|
|
|
--- ui/views/view.h
|
|
|
|
+++ ui/views/view.h
|
2020-03-30 22:13:42 +02:00
|
|
|
@@ -23,6 +23,7 @@
|
2017-05-31 17:33:30 +02:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/macros.h"
|
2020-03-30 22:13:42 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2017-05-31 17:33:30 +02:00
|
|
|
+#include "base/supports_user_data.h"
|
|
|
|
#include "build/build_config.h"
|
2019-01-17 10:56:52 +01:00
|
|
|
#include "third_party/skia/include/core/SkPath.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "ui/accessibility/ax_enums.mojom-forward.h"
|
2020-03-04 01:29:39 +01:00
|
|
|
@@ -273,6 +274,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
|
2020-03-30 22:13:42 +02:00
|
|
|
public ui::EventTarget,
|
2017-07-27 01:19:27 +02:00
|
|
|
public ui::EventHandler,
|
2019-06-05 16:15:45 +02:00
|
|
|
public ui::PropertyHandler,
|
2020-03-04 01:29:39 +01:00
|
|
|
+ public base::SupportsUserData,
|
2020-03-30 22:13:42 +02:00
|
|
|
public views::metadata::MetaDataProvider {
|
2017-05-31 17:33:30 +02:00
|
|
|
public:
|
|
|
|
using Views = std::vector<View*>;
|