cef/patch/patches/views_menu_2102.patch

245 lines
9.5 KiB
Diff

diff --git ui/base/models/menu_model.h ui/base/models/menu_model.h
index 0755f27..72db677 100644
--- 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 {
@@ -115,6 +116,15 @@ class UI_BASE_EXPORT MenuModel {
// |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) {}
+
// Called when the menu is about to be shown.
virtual void MenuWillShow() {}
diff --git ui/views/controls/label.cc ui/views/controls/label.cc
index 9b04c09..5d99c81 100644
--- ui/views/controls/label.cc
+++ ui/views/controls/label.cc
@@ -28,6 +28,7 @@
#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"
#include "ui/views/controls/menu/menu_runner.h"
@@ -36,6 +37,25 @@
#include "ui/views/selection_controller.h"
namespace views {
+
+namespace {
+
+// 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();
+}
+
+} // namespace
+
// static
const char Label::kViewClassName[] = "Label";
const int Label::kFocusBorderPadding = 1;
@@ -210,6 +230,14 @@ void Label::SetElideBehavior(gfx::ElideBehavior elide_behavior) {
ResetLayout();
}
+void Label::SetDrawStringsFlags(int flags) {
+ if (draw_strings_flags_ == flags)
+ return;
+ is_first_paint_text_ = true;
+ draw_strings_flags_ = flags;
+ ResetLayout();
+}
+
void Label::SetTooltipText(const base::string16& tooltip_text) {
DCHECK(handles_tooltips_);
tooltip_text_ = tooltip_text;
@@ -440,7 +468,19 @@ std::unique_ptr<gfx::RenderText> Label::CreateRenderText(
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
index 6293cff..d0a5a8f 100644
--- ui/views/controls/label.h
+++ ui/views/controls/label.h
@@ -117,6 +117,10 @@ class VIEWS_EXPORT Label : public View,
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
@@ -333,6 +337,7 @@ class VIEWS_EXPORT Label : public View,
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.
diff --git ui/views/controls/menu/menu_controller.cc ui/views/controls/menu/menu_controller.cc
index 79ff77c..a0582c0 100644
--- ui/views/controls/menu/menu_controller.cc
+++ ui/views/controls/menu/menu_controller.cc
@@ -2254,8 +2254,13 @@ MenuItemView* MenuController::FindNextSelectableMenuItem(
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);
@@ -2270,8 +2275,10 @@ void MenuController::OpenSubmenuChangeSelectionIfCan() {
void MenuController::CloseSubmenu() {
MenuItemView* item = state_.item;
DCHECK(item);
- if (!item->GetParentMenuItem())
+ if (!item->GetParentMenuItem()) {
+ item->GetDelegate()->OnUnhandledCloseSubmenu(item, base::i18n::IsRTL());
return;
+ }
if (item->HasSubmenu() && item->GetSubmenu()->IsShowing())
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
index 3b7cb7f..3ad68d0 100644
--- ui/views/controls/menu/menu_delegate.h
+++ ui/views/controls/menu/menu_delegate.h
@@ -229,6 +229,11 @@ class VIEWS_EXPORT MenuDelegate {
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);
diff --git ui/views/controls/menu/menu_model_adapter.cc ui/views/controls/menu/menu_model_adapter.cc
index bc04dcb..b2ec114 100644
--- ui/views/controls/menu/menu_model_adapter.cc
+++ ui/views/controls/menu/menu_model_adapter.cc
@@ -245,6 +245,49 @@ void MenuModelAdapter::SelectionChanged(MenuItemView* menu) {
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();
+}
+
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
index c9799da..c7ecca6 100644
--- ui/views/controls/menu/menu_model_adapter.h
+++ ui/views/controls/menu/menu_model_adapter.h
@@ -76,6 +76,13 @@ class VIEWS_EXPORT MenuModelAdapter : public MenuDelegate {
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;
void WillShowMenu(MenuItemView* menu) override;
void WillHideMenu(MenuItemView* menu) override;
void OnMenuClosed(MenuItemView* menu, MenuRunner::RunResult result) override;