2017-02-22 19:05:27 +01:00
|
|
|
diff --git ui/base/models/menu_model.h ui/base/models/menu_model.h
|
2017-09-06 23:40:58 +02:00
|
|
|
index 0755f2752f1d..0322b8c638e7 100644
|
2017-02-22 19:05:27 +01:00
|
|
|
--- ui/base/models/menu_model.h
|
|
|
|
+++ ui/base/models/menu_model.h
|
|
|
|
@@ -15,6 +15,7 @@
|
|
|
|
namespace gfx {
|
|
|
|
class FontList;
|
|
|
|
class Image;
|
|
|
|
+class Point;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ui {
|
2017-03-03 23:37:23 +01:00
|
|
|
@@ -115,6 +116,27 @@ class UI_BASE_EXPORT 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
|
2017-09-06 23:40:58 +02:00
|
|
|
index f8999eb9f61c..dff78c1ca921 100644
|
2017-02-24 21:01:42 +01:00
|
|
|
--- ui/gfx/render_text.cc
|
|
|
|
+++ ui/gfx/render_text.cc
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -495,6 +495,14 @@ void RenderText::SetElideBehavior(ElideBehavior elide_behavior) {
|
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;
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -1395,6 +1403,19 @@ void RenderText::OnTextAttributeChanged() {
|
2017-02-24 21:01:42 +01:00
|
|
|
if (!multiline_ && replace_newline_chars_with_symbols_)
|
|
|
|
base::ReplaceChars(layout_text_, kNewline, kNewlineSymbol, &layout_text_);
|
|
|
|
|
|
|
|
+ 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);
|
|
|
|
+ styles_[gfx::UNDERLINE].ApplyValue(true, range);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
OnLayoutTextAttributeChanged(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git ui/gfx/render_text.h ui/gfx/render_text.h
|
2017-09-06 23:40:58 +02:00
|
|
|
index 024c73ed1ac3..29ad09f7c2f0 100644
|
2017-02-24 21:01:42 +01:00
|
|
|
--- ui/gfx/render_text.h
|
|
|
|
+++ ui/gfx/render_text.h
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -276,6 +276,10 @@ class GFX_EXPORT RenderText {
|
2017-02-24 21:01:42 +01:00
|
|
|
void SetElideBehavior(ElideBehavior elide_behavior);
|
|
|
|
ElideBehavior elide_behavior() const { return elide_behavior_; }
|
|
|
|
|
|
|
|
+ // 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);
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -828,6 +832,8 @@ class GFX_EXPORT RenderText {
|
2017-07-27 01:19:27 +02:00
|
|
|
// The ratio of strike-through line thickness to text height.
|
|
|
|
SkScalar strike_thickness_factor_;
|
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
|
2017-09-06 23:40:58 +02:00
|
|
|
index 8ac475fa752c..ec58c2b28441 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
|
2017-08-04 00:55:19 +02:00
|
|
|
@@ -67,6 +67,8 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost {
|
|
|
|
// them.
|
|
|
|
void AnimateInkDrop(InkDropState state, const ui::LocatedEvent* event);
|
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:
|
|
|
|
static constexpr int kInkDropSmallCornerRadius = 2;
|
|
|
|
static constexpr int kInkDropLargeCornerRadius = 4;
|
2017-02-24 21:01:42 +01:00
|
|
|
diff --git ui/views/controls/button/label_button.cc ui/views/controls/button/label_button.cc
|
2017-09-06 23:40:58 +02:00
|
|
|
index 68be16e39a1d..8038f932444d 100644
|
2017-02-24 21:01:42 +01:00
|
|
|
--- ui/views/controls/button/label_button.cc
|
|
|
|
+++ ui/views/controls/button/label_button.cc
|
2017-07-27 01:19:27 +02:00
|
|
|
@@ -188,6 +188,7 @@ gfx::Size LabelButton::CalculatePreferredSize() const {
|
2017-04-20 21:28:17 +02:00
|
|
|
Label label(GetText(), {label_->font_list()});
|
|
|
|
label.SetLineHeight(label_->line_height());
|
2017-02-24 21:01:42 +01:00
|
|
|
label.SetShadows(label_->shadows());
|
|
|
|
+ label.SetDrawStringsFlags(label_->draw_strings_flags());
|
|
|
|
|
|
|
|
if (style_ == STYLE_BUTTON && PlatformStyle::kDefaultLabelButtonHasBoldFont) {
|
|
|
|
// Some text appears wider when rendered normally than when rendered bold.
|
2017-08-08 22:10:24 +02:00
|
|
|
@@ -399,6 +400,12 @@ std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight()
|
2017-05-31 17:33:30 +02:00
|
|
|
gfx::RectF(image()->GetMirroredBounds()).CenterPoint());
|
|
|
|
}
|
|
|
|
|
|
|
|
+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
|
2017-09-06 23:40:58 +02:00
|
|
|
index bc5190a4bc76..053cb7ce900b 100644
|
2017-05-31 17:33:30 +02:00
|
|
|
--- ui/views/controls/button/label_button.h
|
|
|
|
+++ ui/views/controls/button/label_button.h
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -105,6 +105,9 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
|
2017-05-31 17:33:30 +02:00
|
|
|
std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override;
|
|
|
|
std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override;
|
|
|
|
|
|
|
|
+ // Sets the font list used by this button.
|
|
|
|
+ void SetFontList(const gfx::FontList& font_list);
|
|
|
|
+
|
|
|
|
protected:
|
|
|
|
ImageView* image() const { return image_; }
|
2017-07-27 01:19:27 +02:00
|
|
|
Label* label() const;
|
2017-05-31 17:33:30 +02:00
|
|
|
diff --git ui/views/controls/button/menu_button.cc ui/views/controls/button/menu_button.cc
|
2017-09-06 23:40:58 +02:00
|
|
|
index 8a823199304a..c1c6d3d8972d 100644
|
2017-05-31 17:33:30 +02:00
|
|
|
--- ui/views/controls/button/menu_button.cc
|
|
|
|
+++ ui/views/controls/button/menu_button.cc
|
2017-07-27 01:19:27 +02:00
|
|
|
@@ -186,7 +186,7 @@ bool MenuButton::IsTriggerableEventType(const ui::Event& event) {
|
|
|
|
gfx::Size MenuButton::CalculatePreferredSize() const {
|
|
|
|
gfx::Size prefsize = LabelButton::CalculatePreferredSize();
|
2017-05-31 17:33:30 +02:00
|
|
|
if (show_menu_marker_) {
|
|
|
|
- prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft +
|
|
|
|
+ prefsize.Enlarge(menu_marker_->width() + GetMarkerPaddingLeft() +
|
|
|
|
kMenuMarkerPaddingRight,
|
|
|
|
0);
|
|
|
|
}
|
2017-07-27 01:19:27 +02:00
|
|
|
@@ -316,7 +316,7 @@ gfx::Rect MenuButton::GetChildAreaBounds() {
|
2017-05-31 17:33:30 +02:00
|
|
|
gfx::Size s = size();
|
|
|
|
|
|
|
|
if (show_menu_marker_) {
|
|
|
|
- s.set_width(s.width() - menu_marker_->width() - kMenuMarkerPaddingLeft -
|
|
|
|
+ s.set_width(s.width() - menu_marker_->width() - GetMarkerPaddingLeft() -
|
|
|
|
kMenuMarkerPaddingRight);
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
@@ -413,4 +413,10 @@ int MenuButton::GetMaximumScreenXCoordinate() {
|
2017-05-31 17:33:30 +02:00
|
|
|
return monitor_bounds.right() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+int MenuButton::GetMarkerPaddingLeft() const {
|
|
|
|
+ if (!image()->GetImage().isNull() || !label()->text().empty())
|
|
|
|
+ return kMenuMarkerPaddingLeft;
|
|
|
|
+ return kMenuMarkerPaddingRight;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
} // namespace views
|
|
|
|
diff --git ui/views/controls/button/menu_button.h ui/views/controls/button/menu_button.h
|
2017-09-06 23:40:58 +02:00
|
|
|
index e38200b8a43a..f40b079f82ec 100644
|
2017-05-31 17:33:30 +02:00
|
|
|
--- ui/views/controls/button/menu_button.h
|
|
|
|
+++ ui/views/controls/button/menu_button.h
|
|
|
|
@@ -57,6 +57,9 @@ class VIEWS_EXPORT MenuButton : public LabelButton {
|
|
|
|
~MenuButton() override;
|
|
|
|
|
|
|
|
bool show_menu_marker() const { return show_menu_marker_; }
|
|
|
|
+ void set_show_menu_marker(bool show_menu_marker) {
|
|
|
|
+ show_menu_marker_ = show_menu_marker;
|
|
|
|
+ }
|
|
|
|
void set_menu_marker(const gfx::ImageSkia* menu_marker) {
|
|
|
|
menu_marker_ = menu_marker;
|
|
|
|
}
|
|
|
|
@@ -121,6 +124,9 @@ class VIEWS_EXPORT MenuButton : public LabelButton {
|
|
|
|
// use this to make sure a menu is never shown off screen.
|
|
|
|
int GetMaximumScreenXCoordinate();
|
|
|
|
|
|
|
|
+ // Only apply left padding if there's an image or label.
|
|
|
|
+ int GetMarkerPaddingLeft() const;
|
|
|
|
+
|
|
|
|
// We use a time object in order to keep track of when the menu was closed.
|
|
|
|
// The time is used for simulating menu behavior for the menu button; that
|
|
|
|
// is, if the menu is shown and the button is pressed, we need to close the
|
2017-02-23 21:24:45 +01:00
|
|
|
diff --git ui/views/controls/label.cc ui/views/controls/label.cc
|
2017-09-06 23:40:58 +02:00
|
|
|
index 16aec515d729..a75ddb9802bb 100644
|
2017-02-23 21:24:45 +01:00
|
|
|
--- ui/views/controls/label.cc
|
|
|
|
+++ ui/views/controls/label.cc
|
2017-05-31 17:33:30 +02:00
|
|
|
@@ -26,6 +26,7 @@
|
2017-02-23 21:24:45 +01:00
|
|
|
#include "ui/gfx/color_utils.h"
|
|
|
|
#include "ui/gfx/geometry/insets.h"
|
|
|
|
#include "ui/gfx/text_elider.h"
|
|
|
|
+#include "ui/gfx/text_utils.h"
|
|
|
|
#include "ui/native_theme/native_theme.h"
|
|
|
|
#include "ui/strings/grit/ui_strings.h"
|
2017-03-03 23:37:23 +01:00
|
|
|
#include "ui/views/background.h"
|
2017-05-31 17:33:30 +02:00
|
|
|
@@ -42,6 +43,20 @@ namespace {
|
|
|
|
gfx::Insets NonBorderInsets(const Label& label) {
|
|
|
|
return label.GetInsets() - label.View::GetInsets();
|
|
|
|
}
|
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);
|
|
|
|
+ }
|
|
|
|
+ return gfx::Range::InvalidRange();
|
|
|
|
+}
|
2017-05-31 17:33:30 +02:00
|
|
|
} // namespace
|
|
|
|
|
2017-02-23 21:24:45 +01:00
|
|
|
const char Label::kViewClassName[] = "Label";
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -227,6 +242,15 @@ void Label::SetElideBehavior(gfx::ElideBehavior elide_behavior) {
|
2017-02-23 21:24:45 +01:00
|
|
|
ResetLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
+void Label::SetDrawStringsFlags(int flags) {
|
|
|
|
+ if (draw_strings_flags_ == flags)
|
|
|
|
+ return;
|
|
|
|
+ is_first_paint_text_ = true;
|
|
|
|
+ draw_strings_flags_ = flags;
|
2017-02-24 21:01:42 +01:00
|
|
|
+ render_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_);
|
|
|
|
tooltip_text_ = tooltip_text;
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -454,7 +478,19 @@ std::unique_ptr<gfx::RenderText> Label::CreateRenderText(
|
2017-02-23 21:24:45 +01:00
|
|
|
render_text->SetFontList(font_list());
|
|
|
|
render_text->set_shadows(shadows());
|
|
|
|
render_text->SetCursorEnabled(false);
|
|
|
|
- render_text->SetText(text);
|
|
|
|
+
|
|
|
|
+ if (draw_strings_flags_ != 0) {
|
|
|
|
+ base::string16 text_str = text;
|
|
|
|
+ gfx::Range range = StripAcceleratorChars(draw_strings_flags_, &text_str);
|
|
|
|
+ render_text->SetText(text_str);
|
|
|
|
+ if (range.IsValid()) {
|
|
|
|
+ render_text->SetDisplayRect(bounds());
|
|
|
|
+ render_text->ApplyStyle(gfx::UNDERLINE, true, range);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ render_text->SetText(text);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
return render_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git ui/views/controls/label.h ui/views/controls/label.h
|
2017-09-06 23:40:58 +02:00
|
|
|
index 7cae587453c0..33d15cd4bc59 100644
|
2017-02-23 21:24:45 +01:00
|
|
|
--- ui/views/controls/label.h
|
|
|
|
+++ ui/views/controls/label.h
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -151,6 +151,10 @@ class VIEWS_EXPORT Label : public View,
|
2017-02-23 21:24:45 +01:00
|
|
|
void SetElideBehavior(gfx::ElideBehavior elide_behavior);
|
|
|
|
gfx::ElideBehavior elide_behavior() const { return elide_behavior_; }
|
|
|
|
|
|
|
|
+ // Get or set the flags that control display of accelerator characters.
|
|
|
|
+ void SetDrawStringsFlags(int flags);
|
|
|
|
+ int draw_strings_flags() const { return draw_strings_flags_; }
|
|
|
|
+
|
|
|
|
// 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 revert to
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -371,6 +375,7 @@ class VIEWS_EXPORT Label : public View,
|
2017-02-23 21:24:45 +01:00
|
|
|
bool collapse_when_hidden_;
|
|
|
|
int fixed_width_;
|
|
|
|
int max_width_;
|
|
|
|
+ int draw_strings_flags_ = 0;
|
|
|
|
|
|
|
|
// TODO(ckocagil): Remove is_first_paint_text_ before crbug.com/441028 is
|
|
|
|
// closed.
|
2017-02-22 19:05:27 +01:00
|
|
|
diff --git ui/views/controls/menu/menu_controller.cc ui/views/controls/menu/menu_controller.cc
|
2017-09-06 23:40:58 +02:00
|
|
|
index 9c0a30130cdc..36f1e4db0ad0 100644
|
2017-02-22 19:05:27 +01:00
|
|
|
--- ui/views/controls/menu/menu_controller.cc
|
|
|
|
+++ ui/views/controls/menu/menu_controller.cc
|
2017-07-27 01:19:27 +02:00
|
|
|
@@ -2267,8 +2267,13 @@ MenuItemView* MenuController::FindNextSelectableMenuItem(
|
2017-02-22 19:05:27 +01:00
|
|
|
|
|
|
|
void MenuController::OpenSubmenuChangeSelectionIfCan() {
|
|
|
|
MenuItemView* item = pending_state_.item;
|
|
|
|
- if (!item->HasSubmenu() || !item->enabled())
|
|
|
|
+ if (!item->HasSubmenu() || !item->enabled() || !item->GetParentMenuItem()) {
|
|
|
|
+ MenuItemView* submenu_item =
|
|
|
|
+ item->GetParentMenuItem() ? item->GetParentMenuItem() : item;
|
|
|
|
+ submenu_item->GetDelegate()->OnUnhandledOpenSubmenu(submenu_item,
|
|
|
|
+ base::i18n::IsRTL());
|
|
|
|
return;
|
|
|
|
+ }
|
|
|
|
MenuItemView* to_select = NULL;
|
|
|
|
if (item->GetSubmenu()->GetMenuItemCount() > 0)
|
|
|
|
to_select = FindInitialSelectableMenuItem(item, INCREMENT_SELECTION_DOWN);
|
2017-07-27 01:19:27 +02:00
|
|
|
@@ -2283,8 +2288,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
|
2017-09-06 23:40:58 +02:00
|
|
|
index 4dea63f9f286..ef50b710c5af 100644
|
2017-02-22 19:05:27 +01:00
|
|
|
--- ui/views/controls/menu/menu_delegate.h
|
|
|
|
+++ ui/views/controls/menu/menu_delegate.h
|
2017-03-03 23:37:23 +01:00
|
|
|
@@ -10,6 +10,7 @@
|
2017-02-25 06:03:31 +01:00
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/strings/string16.h"
|
|
|
|
+#include "third_party/skia/include/core/SkColor.h"
|
|
|
|
#include "ui/base/dragdrop/drag_drop_types.h"
|
|
|
|
#include "ui/base/dragdrop/os_exchange_data.h"
|
|
|
|
#include "ui/base/ui_base_types.h"
|
2017-05-31 17:33:30 +02:00
|
|
|
@@ -76,6 +77,22 @@ class VIEWS_EXPORT MenuDelegate {
|
2017-03-03 23:37:23 +01:00
|
|
|
// it's disabled.
|
|
|
|
virtual bool GetShouldUseNormalForegroundColor(int command_id) 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,
|
2017-03-03 23:37:23 +01:00
|
|
|
@@ -208,6 +225,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
|
2017-09-06 23:40:58 +02:00
|
|
|
index fcf1e9aa0b74..dd4f65849feb 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
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -810,7 +810,12 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
|
2017-03-03 23:37:23 +01:00
|
|
|
// only need the background when we want it to look different, as when we're
|
|
|
|
// selected.
|
|
|
|
ui::NativeTheme* native_theme = GetNativeTheme();
|
|
|
|
- if (render_selection) {
|
|
|
|
+ SkColor override_color;
|
|
|
|
+ if (delegate && delegate->GetBackgroundColor(GetCommand(),
|
|
|
|
+ render_selection,
|
|
|
|
+ &override_color)) {
|
|
|
|
+ canvas->DrawColor(override_color);
|
|
|
|
+ } else if (render_selection) {
|
|
|
|
gfx::Rect item_bounds(0, 0, width(), height());
|
|
|
|
AdjustBoundsForRTLUI(&item_bounds);
|
2017-02-25 06:03:31 +01:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -899,6 +904,13 @@ void MenuItemView::PaintMinorText(gfx::Canvas* canvas, SkColor color) {
|
2017-03-03 23:37:23 +01:00
|
|
|
SkColor MenuItemView::GetTextColor(bool minor,
|
|
|
|
bool render_selection,
|
|
|
|
bool emphasized) 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
|
|
|
+ }
|
|
|
|
+
|
2017-03-03 23:37:23 +01:00
|
|
|
ui::NativeTheme::ColorId color_id =
|
|
|
|
minor ? ui::NativeTheme::kColorId_MenuItemSubtitleColor
|
|
|
|
: ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor;
|
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
|
2017-09-06 23:40:58 +02:00
|
|
|
index 06a9d3cfda9b..c602a13efd6a 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
|
2017-03-03 23:37:23 +01:00
|
|
|
@@ -245,6 +245,77 @@ void MenuModelAdapter::SelectionChanged(MenuItemView* menu) {
|
2017-02-22 19:05:27 +01:00
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
+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
|
2017-09-06 23:40:58 +02:00
|
|
|
index 0ac493c3c6a0..741769e90eb0 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
|
2017-03-03 23:37:23 +01:00
|
|
|
@@ -76,6 +76,20 @@ class VIEWS_EXPORT MenuModelAdapter : public MenuDelegate {
|
2017-02-22 19:05:27 +01:00
|
|
|
bool IsCommandVisible(int id) const override;
|
|
|
|
bool IsItemChecked(int id) const override;
|
|
|
|
void SelectionChanged(MenuItemView* menu) 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
|
2017-09-06 23:40:58 +02:00
|
|
|
index 08ba198141b2..595b3750c544 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
|
|
|
|
@@ -184,6 +184,11 @@ MenuScrollViewContainer::MenuScrollViewContainer(SubmenuView* content_view)
|
|
|
|
scroll_view_ = new MenuScrollView(content_view);
|
|
|
|
AddChildView(scroll_view_);
|
|
|
|
|
|
|
|
+ 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
|
2017-09-06 23:40:58 +02:00
|
|
|
index 534e0c4cb41d..974d82da99cb 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
|
2017-07-27 01:19:27 +02:00
|
|
|
@@ -147,10 +147,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
|
2017-09-06 23:40:58 +02:00
|
|
|
index 33f393275cbc..67cc5d64c58d 100644
|
2017-05-31 17:33:30 +02:00
|
|
|
--- ui/views/view.h
|
|
|
|
+++ ui/views/view.h
|
|
|
|
@@ -18,6 +18,7 @@
|
|
|
|
#include "base/i18n/rtl.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/macros.h"
|
|
|
|
+#include "base/supports_user_data.h"
|
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "ui/accessibility/ax_enums.h"
|
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
2017-09-06 23:40:58 +02:00
|
|
|
@@ -118,7 +119,8 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
|
2017-05-31 17:33:30 +02:00
|
|
|
public ui::AcceleratorTarget,
|
|
|
|
public ui::EventTarget,
|
2017-07-27 01:19:27 +02:00
|
|
|
public ui::EventHandler,
|
|
|
|
- public ui::PropertyHandler {
|
|
|
|
+ public ui::PropertyHandler,
|
2017-05-31 17:33:30 +02:00
|
|
|
+ public base::SupportsUserData {
|
|
|
|
public:
|
|
|
|
using Views = std::vector<View*>;
|
|
|
|
|