diff --git chrome/browser/ui/views/toolbar/app_menu.cc chrome/browser/ui/views/toolbar/app_menu.cc index b7dff19efeee6..2ff00fe179839 100644 --- chrome/browser/ui/views/toolbar/app_menu.cc +++ chrome/browser/ui/views/toolbar/app_menu.cc @@ -1043,7 +1043,9 @@ void AppMenu::RunMenu(views::MenuButtonController* host) { host->button()->GetWidget(), host, host->button()->GetAnchorBoundsInScreen(), views::MenuAnchorPosition::kTopRight, ui::mojom::MenuSourceType::kNone, - /*native_view_for_gestures=*/gfx::NativeView(), /*corners=*/std::nullopt, + /*native_view_for_gestures=*/gfx::NativeView(), + /*parent_widget=*/gfx::kNullAcceleratedWidget, + /*corners=*/std::nullopt, "Chrome.AppMenu.MenuHostInitToNextFramePresented"); } diff --git ui/base/models/menu_model.h ui/base/models/menu_model.h index ecd8177fd48cb..63d94b6f39a7b 100644 --- ui/base/models/menu_model.h +++ ui/base/models/menu_model.h @@ -17,8 +17,11 @@ #include "ui/color/color_id.h" #include "ui/gfx/native_widget_types.h" +#include "third_party/skia/include/core/SkColor.h" + namespace gfx { class FontList; +class Point; } namespace ui { @@ -153,6 +156,27 @@ class COMPONENT_EXPORT(UI_BASE) MenuModel { // |event_flags| is a bit mask of ui::EventFlags. virtual void ActivatedAt(size_t 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) {} + + // Override the text/background color of a given menu item dependent on the + // |index| 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(size_t index, + bool is_minor, + bool is_hovered, + SkColor* override_color) const { return false; } + virtual bool GetBackgroundColor(size_t index, + bool is_hovered, + SkColor* override_color) const + { return false; } + // Called when the menu is about to be shown. virtual void MenuWillShow() {} diff --git ui/gfx/render_text.cc ui/gfx/render_text.cc index ec4c6eb4e76dd..1b74741b8b2ff 100644 --- ui/gfx/render_text.cc +++ ui/gfx/render_text.cc @@ -707,6 +707,14 @@ void RenderText::SetWhitespaceElision(std::optional whitespace_elision) { } } +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; @@ -2144,6 +2152,18 @@ void RenderText::OnTextAttributeChanged() { text_elided_ = false; layout_text_up_to_date_ = false; + 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::LocateAndRemoveAcceleratorChar(layout_text_, &char_pos, &char_span); + if (char_pos != -1) { + gfx::Range range(char_pos, char_pos + char_span); + styles_[TEXT_STYLE_UNDERLINE].ApplyValue(true, range); + } + } OnLayoutTextAttributeChanged(); } diff --git ui/gfx/render_text.h ui/gfx/render_text.h index 624a22c8c5478..707aca5f8342a 100644 --- ui/gfx/render_text.h +++ ui/gfx/render_text.h @@ -360,6 +360,10 @@ class COMPONENT_EXPORT(GFX) RenderText { void SetWhitespaceElision(std::optional elide_whitespace); std::optional whitespace_elision() const { return whitespace_elision_; } + // 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); @@ -1107,6 +1111,8 @@ class COMPONENT_EXPORT(GFX) RenderText { // Tell whether or not the |layout_text_| needs an update or is up to date. mutable bool layout_text_up_to_date_ = false; + + int draw_strings_flags_ = 0; }; } // namespace gfx diff --git ui/views/animation/ink_drop_host.h ui/views/animation/ink_drop_host.h index c579f65dce9f0..a04e0d1f66aaa 100644 --- ui/views/animation/ink_drop_host.h +++ ui/views/animation/ink_drop_host.h @@ -194,6 +194,8 @@ class VIEWS_EXPORT InkDropHost { View* host_view() { return host_view_; } const View* host_view() const { return host_view_; } + InkDropMode ink_drop_mode() const { return ink_drop_mode_; } + private: friend class test::InkDropHostTestApi; diff --git ui/views/controls/button/label_button.cc ui/views/controls/button/label_button.cc index f0ba9bff47d86..06d5803a77c3f 100644 --- ui/views/controls/button/label_button.cc +++ ui/views/controls/button/label_button.cc @@ -611,6 +611,12 @@ void LabelButton::OnThemeChanged() { SchedulePaint(); } +void LabelButton::SetFontList(const gfx::FontList& font_list) { + cached_normal_font_list_ = font_list; + cached_default_button_font_list_ = font_list; + label_->SetFontList(cached_normal_font_list_); +} + void LabelButton::StateChanged(ButtonState old_state) { Button::StateChanged(old_state); ResetLabelEnabledColor(); diff --git ui/views/controls/button/label_button.h ui/views/controls/button/label_button.h index 4a6ec6307fb8b..c01c1eb2f9853 100644 --- ui/views/controls/button/label_button.h +++ ui/views/controls/button/label_button.h @@ -188,6 +188,9 @@ class VIEWS_EXPORT LabelButton : public Button, // widget, and the parent of the containing widget. ButtonState GetVisualState() const; + // Sets the font list used by this button. + void SetFontList(const gfx::FontList& font_list); + protected: LabelButtonImageContainer* image_container() { return image_container_.get(); diff --git ui/views/controls/label.cc ui/views/controls/label.cc index f97a2d37d2ef5..6ef612c096dfb 100644 --- ui/views/controls/label.cc +++ ui/views/controls/label.cc @@ -52,12 +52,29 @@ enum LabelPropertyKey { kLabelObscured, kLabelAllowCharacterBreak, kAccessibleTextOffsets, + kLabelDrawStringsFlags, }; bool IsOpaque(SkColor color) { return SkColorGetA(color) == SK_AlphaOPAQUE; } +// 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, std::u16string* text) { + if (flags & (gfx::Canvas::SHOW_PREFIX | gfx::Canvas::HIDE_PREFIX)) { + int char_pos = -1; + int char_span = 0; + *text = gfx::LocateAndRemoveAcceleratorChar(*text, &char_pos, &char_span); + if ((flags & gfx::Canvas::SHOW_PREFIX) && char_pos != -1) { + return gfx::Range(static_cast(char_pos), + static_cast(char_pos + char_span)); + } + } + return gfx::Range::InvalidRange(); +} + } // namespace namespace views { @@ -532,6 +549,15 @@ void Label::SetElideBehavior(gfx::ElideBehavior elide_behavior) { OnDisplayTextTruncation(); } +void Label::SetDrawStringsFlags(int flags) { + if (draw_strings_flags_ == flags) + return; + draw_strings_flags_ = flags; + full_text_->SetDrawStringsFlags(draw_strings_flags_); + OnPropertyChanged(&full_text_ + kLabelDrawStringsFlags, + kPropertyEffectsPreferredSizeChanged); +} + std::u16string Label::GetTooltipText() const { return GetCachedTooltipText(); } @@ -863,6 +889,16 @@ std::unique_ptr Label::CreateRenderText() const { render_text->SelectRange(stored_selection_range_); } + if (draw_strings_flags_ != 0) { + auto text_str = GetText(); + 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::TEXT_STYLE_UNDERLINE, true, range); + } + } + return render_text; } diff --git ui/views/controls/label.h ui/views/controls/label.h index 7457d09c12b8c..8f320e892a571 100644 --- ui/views/controls/label.h +++ ui/views/controls/label.h @@ -246,6 +246,10 @@ class VIEWS_EXPORT Label : public View, gfx::ElideBehavior GetElideBehavior() const; void SetElideBehavior(gfx::ElideBehavior elide_behavior); + // Get or set the flags that control display of accelerator characters. + void SetDrawStringsFlags(int flags); + int GetDrawStringsFlags() const { return draw_strings_flags_; } + // Gets/Sets the custom local 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 @@ -548,6 +552,7 @@ class VIEWS_EXPORT Label : public View, int max_width_ = 0; // This is used in single-line mode. int max_width_single_line_ = 0; + int draw_strings_flags_ = 0; std::unique_ptr selection_controller_; diff --git ui/views/controls/menu/menu_controller.cc ui/views/controls/menu/menu_controller.cc index 3a406a6489f42..e937ca0d2890e 100644 --- ui/views/controls/menu/menu_controller.cc +++ ui/views/controls/menu/menu_controller.cc @@ -579,7 +579,8 @@ void MenuController::Run(Widget* parent, ui::mojom::MenuSourceType source_type, bool context_menu, bool is_nested_drag, - gfx::NativeView native_view_for_gestures) { + gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget) { exit_type_ = ExitType::kNone; possible_drag_ = false; drag_in_progress_ = false; @@ -629,6 +630,7 @@ void MenuController::Run(Widget* parent, owner_->AddObserver(this); native_view_for_gestures_ = native_view_for_gestures; + parent_widget_ = parent_widget; // Only create a MenuPreTargetHandler for non-nested menus. Nested menus // will use the existing one. @@ -2279,6 +2281,7 @@ void MenuController::OpenMenuImpl(MenuItemView* item, bool show) { params.do_capture = do_capture; params.native_view_for_gestures = native_view_for_gestures_; params.owned_window_anchor = anchor; + params.parent_widget = parent_widget_; if (item->GetParentMenuItem()) { params.context = item->GetWidget(); // (crbug.com/1414232) The item to be open is a submenu. Make sure @@ -2972,8 +2975,13 @@ MenuItemView* MenuController::FindInitialSelectableMenuItem( void MenuController::OpenSubmenuChangeSelectionIfCan() { MenuItemView* item = pending_state_.item; - if (!item->HasSubmenu() || !item->GetEnabled()) + if (!item->HasSubmenu() || !item->GetEnabled() || !item->GetParentMenuItem()) { + MenuItemView* submenu_item = + item->GetParentMenuItem() ? item->GetParentMenuItem() : item; + submenu_item->GetDelegate()->OnUnhandledOpenSubmenu(submenu_item, + base::i18n::IsRTL()); return; + } // Show the sub-menu. SetSelection(item, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); @@ -2993,8 +3001,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->SubmenuIsShowing()) SetSelection(item, SELECTION_UPDATE_IMMEDIATELY); else if (item->GetParentMenuItem()->GetParentMenuItem()) diff --git ui/views/controls/menu/menu_controller.h ui/views/controls/menu/menu_controller.h index 737b5dd9a243e..44b088afd01c8 100644 --- ui/views/controls/menu/menu_controller.h +++ ui/views/controls/menu/menu_controller.h @@ -140,7 +140,8 @@ class VIEWS_EXPORT MenuController final : public gfx::AnimationDelegate, ui::mojom::MenuSourceType source_type = ui::mojom::MenuSourceType::kNone, bool context_menu = false, bool is_nested_drag = false, - gfx::NativeView native_view_for_gestures = gfx::NativeView()); + gfx::NativeView native_view_for_gestures = gfx::NativeView(), + gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget); bool for_drop() const { return for_drop_; } @@ -740,6 +741,8 @@ class VIEWS_EXPORT MenuController final : public gfx::AnimationDelegate, // RunType::SEND_GESTURE_EVENTS_TO_OWNER is set. gfx::NativeView native_view_for_gestures_ = gfx::NativeView(); + gfx::AcceleratedWidget parent_widget_ = gfx::kNullAcceleratedWidget; + // Indicates a possible drag operation. bool possible_drag_ = false; diff --git ui/views/controls/menu/menu_delegate.h ui/views/controls/menu/menu_delegate.h index ea82da6dc2f45..575bd9484c2bf 100644 --- ui/views/controls/menu/menu_delegate.h +++ ui/views/controls/menu/menu_delegate.h @@ -73,6 +73,22 @@ class VIEWS_EXPORT MenuDelegate { virtual const gfx::FontList* GetLabelFontList(int id) const; virtual std::optional GetLabelColor(int id) const; + // 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 + // |command_id| and its |is_hovered| state. Returns true if it chooses to + // override the color. + virtual bool GetBackgroundColor(int command_id, + bool is_hovered, + SkColor* override_color) const + { return false; } + // 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. virtual std::u16string GetTooltipText(int id, @@ -201,6 +217,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_host.cc ui/views/controls/menu/menu_host.cc index 4e87636d2778c..0492351fb3e01 100644 --- ui/views/controls/menu/menu_host.cc +++ ui/views/controls/menu/menu_host.cc @@ -148,6 +148,8 @@ void MenuHost::InitMenuHost(const InitParams& init_params) { : gfx::NativeWindow(); params.bounds = init_params.bounds; + params.parent_widget = init_params.parent_widget; + #if defined(USE_AURA) params.init_properties_container.SetProperty(aura::client::kOwnedWindowAnchor, init_params.owned_window_anchor); @@ -155,7 +157,8 @@ void MenuHost::InitMenuHost(const InitParams& init_params) { // If MenuHost has no parent widget, it needs to be marked // Activatable, so that calling Show in ShowMenuHost will // get keyboard focus. - if (init_params.parent == nullptr) + if (init_params.parent == nullptr && + init_params.parent_widget == gfx::kNullAcceleratedWidget) params.activatable = Widget::InitParams::Activatable::kYes; #if BUILDFLAG(IS_WIN) diff --git ui/views/controls/menu/menu_host.h ui/views/controls/menu/menu_host.h index fc1d5fccc3845..c065cafcd537c 100644 --- ui/views/controls/menu/menu_host.h +++ ui/views/controls/menu/menu_host.h @@ -57,6 +57,8 @@ class MenuHost : public Widget, public WidgetObserver { // Additional information that helps to position anchored windows in such // backends as Wayland. ui::OwnedWindowAnchor owned_window_anchor; + + gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget; }; explicit MenuHost(SubmenuView* submenu); diff --git ui/views/controls/menu/menu_item_view.cc ui/views/controls/menu/menu_item_view.cc index b4cd3e5a49763..992314f502a0f 100644 --- ui/views/controls/menu/menu_item_view.cc +++ ui/views/controls/menu/menu_item_view.cc @@ -1113,6 +1113,15 @@ void MenuItemView::PaintBackground(gfx::Canvas* canvas, 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(); + SkColor override_color; + if (delegate && delegate->GetBackgroundColor(GetCommand(), + paint_as_selected, + &override_color)) { + canvas->DrawColor(override_color); } else if (paint_as_selected) { gfx::Rect item_bounds = GetLocalBounds(); if (type_ == Type::kActionableSubMenu) { @@ -1183,6 +1192,13 @@ void MenuItemView::PaintMinorIconAndText(gfx::Canvas* canvas, SkColor color) { } SkColor MenuItemView::GetTextColor(bool minor, bool paint_as_selected) const { + SkColor text_color; + const MenuDelegate *delegate = GetDelegate(); + if (delegate && delegate->GetTextColor(GetCommand(), minor, paint_as_selected, + &text_color)) { + return text_color; + } + // Use a custom color if provided by the controller. If the item is selected, // use the default color. if (!paint_as_selected && foreground_color_id_.has_value()) { diff --git ui/views/controls/menu/menu_model_adapter.cc ui/views/controls/menu/menu_model_adapter.cc index 1041002b24a7b..0216af1096281 100644 --- ui/views/controls/menu/menu_model_adapter.cc +++ ui/views/controls/menu/menu_model_adapter.cc @@ -4,6 +4,7 @@ #include "ui/views/controls/menu/menu_model_adapter.h" +#include #include #include #include @@ -245,6 +246,71 @@ bool MenuModelAdapter::IsItemChecked(int id) const { return model->IsItemCheckedAt(index); } +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 auto map_iterator = menu_map_.find(menu); + if (map_iterator != menu_map_.end()) { + map_iterator->second->MouseOutsideMenu(screen_point); + return nullptr; + } + + NOTREACHED(); +} + +void MenuModelAdapter::OnUnhandledOpenSubmenu(MenuItemView* menu, bool is_rtl) { + // Look up the menu model for this menu. + const auto 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 auto map_iterator = menu_map_.find(menu); + if (map_iterator != menu_map_.end()) { + map_iterator->second->UnhandledCloseSubmenu(is_rtl); + return; + } + + NOTREACHED(); +} + +bool MenuModelAdapter::GetTextColor(int command_id, + bool is_minor, + bool is_hovered, + SkColor* override_color) const { + ui::MenuModel* model = menu_model_; + size_t index = 0; + if (ui::MenuModel::GetModelAndIndexForCommandId(command_id, &model, &index)) + return model->GetTextColor(index, is_minor, is_hovered, override_color); + + // Return the default color. + return menu_model_->GetBackgroundColor(std::numeric_limits::max(), + is_hovered, override_color); +} + +bool MenuModelAdapter::GetBackgroundColor(int command_id, + bool is_hovered, + SkColor* override_color) const { + ui::MenuModel* model = menu_model_; + size_t index = 0; + if (ui::MenuModel::GetModelAndIndexForCommandId(command_id, &model, &index)) + return model->GetBackgroundColor(index, is_hovered, override_color); + + // Return the default color. + return menu_model_->GetBackgroundColor(std::numeric_limits::max(), + is_hovered, override_color); +} + void MenuModelAdapter::WillShowMenu(MenuItemView* menu) { // Look up the menu model for this menu. const std::map corners, std::optional show_menu_host_duration_histogram) { // Do not attempt to show the menu if the application is currently shutting @@ -90,7 +91,7 @@ void MenuRunner::RunMenuAt( } impl_->RunMenuAt(parent, button_controller, bounds, anchor, source_type, - run_types_, native_view_for_gestures, corners, + run_types_, native_view_for_gestures, parent_widget, corners, std::move(show_menu_host_duration_histogram)); } diff --git ui/views/controls/menu/menu_runner.h ui/views/controls/menu/menu_runner.h index 493fda82af500..38d3344d97074 100644 --- ui/views/controls/menu/menu_runner.h +++ ui/views/controls/menu/menu_runner.h @@ -157,6 +157,8 @@ class VIEWS_EXPORT MenuRunner { MenuAnchorPosition anchor, ui::mojom::MenuSourceType source_type, gfx::NativeView native_view_for_gestures = gfx::NativeView(), + gfx::AcceleratedWidget parent_widget = + gfx::kNullAcceleratedWidget, std::optional corners = std::nullopt, std::optional show_menu_host_duration_histogram = std::nullopt); diff --git ui/views/controls/menu/menu_runner_impl.cc ui/views/controls/menu/menu_runner_impl.cc index 13fd4d8b5b536..256b4af43b3ec 100644 --- ui/views/controls/menu/menu_runner_impl.cc +++ ui/views/controls/menu/menu_runner_impl.cc @@ -117,6 +117,7 @@ void MenuRunnerImpl::RunMenuAt( ui::mojom::MenuSourceType source_type, int32_t run_types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget, std::optional corners, std::optional show_menu_host_duration_histogram) { closing_event_time_ = base::TimeTicks(); @@ -190,7 +191,7 @@ void MenuRunnerImpl::RunMenuAt( controller->Run(parent, button_controller, menu_.get(), bounds, anchor, source_type, (run_types & MenuRunner::CONTEXT_MENU) != 0, (run_types & MenuRunner::NESTED_DRAG) != 0, - native_view_for_gestures); + native_view_for_gestures, parent_widget); } void MenuRunnerImpl::Cancel() { diff --git ui/views/controls/menu/menu_runner_impl.h ui/views/controls/menu/menu_runner_impl.h index 5dbd93d7ed343..b82c2beeef701 100644 --- ui/views/controls/menu/menu_runner_impl.h +++ ui/views/controls/menu/menu_runner_impl.h @@ -56,6 +56,7 @@ class VIEWS_EXPORT MenuRunnerImpl : public MenuRunnerImplInterface, ui::mojom::MenuSourceType source_type = ui::mojom::MenuSourceType::kNone, int32_t run_types = MenuRunner::NO_FLAGS, gfx::NativeView native_view_for_gestures = {}, + gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget, std::optional corners = std::nullopt, std::optional show_menu_host_duration_histogram = std::nullopt) override; diff --git ui/views/controls/menu/menu_runner_impl_adapter.cc ui/views/controls/menu/menu_runner_impl_adapter.cc index d23190775a306..8a1467a1f828f 100644 --- ui/views/controls/menu/menu_runner_impl_adapter.cc +++ ui/views/controls/menu/menu_runner_impl_adapter.cc @@ -37,10 +37,11 @@ void MenuRunnerImplAdapter::RunMenuAt( ui::mojom::MenuSourceType source_type, int32_t types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget, std::optional corners, std::optional show_menu_host_duration_histogram) { impl_->RunMenuAt(parent, button_controller, bounds, anchor, source_type, - types, native_view_for_gestures); + types, native_view_for_gestures, parent_widget); } void MenuRunnerImplAdapter::Cancel() { diff --git ui/views/controls/menu/menu_runner_impl_adapter.h ui/views/controls/menu/menu_runner_impl_adapter.h index 16c697fcceeff..c20377c8eb10b 100644 --- ui/views/controls/menu/menu_runner_impl_adapter.h +++ ui/views/controls/menu/menu_runner_impl_adapter.h @@ -47,6 +47,7 @@ class VIEWS_EXPORT MenuRunnerImplAdapter : public MenuRunnerImplInterface { ui::mojom::MenuSourceType source_type = ui::mojom::MenuSourceType::kNone, int32_t run_types = MenuRunner::NO_FLAGS, gfx::NativeView native_view_for_gestures = {}, + gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget, std::optional corners = std::nullopt, std::optional show_menu_host_duration_histogram = std::nullopt) override; diff --git ui/views/controls/menu/menu_runner_impl_cocoa.h ui/views/controls/menu/menu_runner_impl_cocoa.h index e315ccc4cda65..8222030bd21f9 100644 --- ui/views/controls/menu/menu_runner_impl_cocoa.h +++ ui/views/controls/menu/menu_runner_impl_cocoa.h @@ -44,6 +44,7 @@ class VIEWS_EXPORT MenuRunnerImplCocoa : public MenuRunnerImplInterface { ui::mojom::MenuSourceType source_type, int32_t run_types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget, std::optional corners, std::optional show_menu_host_duration_histogram) override; void Cancel() override; diff --git ui/views/controls/menu/menu_runner_impl_cocoa.mm ui/views/controls/menu/menu_runner_impl_cocoa.mm index 52f3f0bc7e703..cf0eec570bd1e 100644 --- ui/views/controls/menu/menu_runner_impl_cocoa.mm +++ ui/views/controls/menu/menu_runner_impl_cocoa.mm @@ -71,6 +71,7 @@ void MenuRunnerImplCocoa::RunMenuAt( ui::mojom::MenuSourceType source_type, int32_t run_types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget /*parent_widget*/, std::optional corners, std::optional show_menu_host_duration_histogram) { DCHECK(!IsRunning()); diff --git ui/views/controls/menu/menu_runner_impl_interface.h ui/views/controls/menu/menu_runner_impl_interface.h index 465f774e1ec90..c99b51b9f0eba 100644 --- ui/views/controls/menu/menu_runner_impl_interface.h +++ ui/views/controls/menu/menu_runner_impl_interface.h @@ -50,6 +50,8 @@ class MenuRunnerImplInterface { ui::mojom::MenuSourceType source_type, int32_t run_types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget = + gfx::kNullAcceleratedWidget, std::optional corners = std::nullopt, std::optional show_menu_host_duration_histogram = std::nullopt) = 0; diff --git ui/views/controls/menu/menu_runner_impl_mac.h ui/views/controls/menu/menu_runner_impl_mac.h index 6b71a13002d27..da0d2bf4dc774 100644 --- ui/views/controls/menu/menu_runner_impl_mac.h +++ ui/views/controls/menu/menu_runner_impl_mac.h @@ -41,6 +41,7 @@ class VIEWS_EXPORT MenuRunnerImplMac : public MenuRunnerImplInterface { ui::mojom::MenuSourceType source_type, int32_t run_types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget, std::optional corners, std::optional show_menu_host_duration_histogram) override; void Cancel() override; diff --git ui/views/controls/menu/menu_runner_impl_mac.mm ui/views/controls/menu/menu_runner_impl_mac.mm index 1b5d97c3f6b49..3da7b69d6f7d0 100644 --- ui/views/controls/menu/menu_runner_impl_mac.mm +++ ui/views/controls/menu/menu_runner_impl_mac.mm @@ -48,6 +48,7 @@ void MenuRunnerImplMac::RunMenuAt( ui::mojom::MenuSourceType source_type, int32_t run_types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget, std::optional corners, std::optional show_menu_host_duration_histogram) { if (!implementation_) { @@ -61,7 +62,8 @@ void MenuRunnerImplMac::RunMenuAt( } implementation_->RunMenuAt(parent, button_controller, bounds, anchor, source_type, run_types, native_view_for_gestures, - corners, show_menu_host_duration_histogram); + parent_widget, corners, + show_menu_host_duration_histogram); } void MenuRunnerImplMac::Cancel() { diff --git ui/views/controls/menu/menu_runner_impl_remote_cocoa.h ui/views/controls/menu/menu_runner_impl_remote_cocoa.h index 9c4a933af7836..cacf9aa1ae144 100644 --- ui/views/controls/menu/menu_runner_impl_remote_cocoa.h +++ ui/views/controls/menu/menu_runner_impl_remote_cocoa.h @@ -59,6 +59,7 @@ class VIEWS_EXPORT MenuRunnerImplRemoteCocoa ui::mojom::MenuSourceType source_type, int32_t run_types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget, std::optional corners, std::optional show_menu_host_duration_histogram) override; void Cancel() override; diff --git ui/views/controls/menu/menu_runner_impl_remote_cocoa.mm ui/views/controls/menu/menu_runner_impl_remote_cocoa.mm index da772edd48c00..43c930e932287 100644 --- ui/views/controls/menu/menu_runner_impl_remote_cocoa.mm +++ ui/views/controls/menu/menu_runner_impl_remote_cocoa.mm @@ -71,6 +71,7 @@ void MenuRunnerImplRemoteCocoa::RunMenuAt( ui::mojom::MenuSourceType source_type, int32_t run_types, gfx::NativeView native_view_for_gestures, + gfx::AcceleratedWidget parent_widget, std::optional corners, std::optional show_menu_host_duration_histogram) { RunMenu(parent, bounds.CenterPoint()); diff --git ui/views/controls/menu/menu_scroll_view_container.cc ui/views/controls/menu/menu_scroll_view_container.cc index 3dc4156dd046c..020f016ffc261 100644 --- ui/views/controls/menu/menu_scroll_view_container.cc +++ ui/views/controls/menu/menu_scroll_view_container.cc @@ -266,6 +266,11 @@ MenuScrollViewContainer::MenuScrollViewContainer(SubmenuView* content_view) scroll_down_button_ = background_view_->AddChildView( std::make_unique(content_view, false)); + SkColor override_color; + MenuDelegate* delegate = content_view_->GetMenuItem()->GetDelegate(); + if (delegate && delegate->GetBackgroundColor(-1, false, &override_color)) + SetBackground(views::CreateSolidBackground(override_color)); + arrow_ = BubbleBorderTypeFromAnchor( content_view_->GetMenuItem()->GetMenuController()->GetAnchorPosition()); diff --git ui/views/test/ui_controls_factory_desktop_aura_ozone.cc ui/views/test/ui_controls_factory_desktop_aura_ozone.cc index 92b86fccb3a30..964351594f1e4 100644 --- ui/views/test/ui_controls_factory_desktop_aura_ozone.cc +++ ui/views/test/ui_controls_factory_desktop_aura_ozone.cc @@ -15,6 +15,7 @@ #include "base/run_loop.h" #include "base/task/single_thread_task_runner.h" #include "build/build_config.h" +#include "cef/libcef/features/features.h" #include "ui/aura/client/screen_position_client.h" #include "ui/aura/env.h" #include "ui/aura/test/aura_test_utils.h" @@ -171,9 +172,11 @@ bool SendMouseMoveNotifyWhenDone(int screen_x, aura::test::QueryLatestMousePositionRequestInHost(host); host->ConvertPixelsToDIP(&root_current_location); +#if !BUILDFLAG(ENABLE_CEF) auto* screen = views::test::TestDesktopScreenOzone::GetInstance(); DCHECK_EQ(screen, display::Screen::GetScreen()); screen->set_cursor_screen_point(gfx::Point(screen_x, screen_y)); +#endif if (root_location != root_current_location && !g_ozone_ui_controls_test_helper->MustUseUiControlsForMoveCursorTo() && diff --git ui/views/view.h ui/views/view.h index 61f50d010646c..8bf476f6f85df 100644 --- ui/views/view.h +++ ui/views/view.h @@ -25,6 +25,7 @@ #include "base/memory/raw_ptr.h" #include "base/memory/safety_checks.h" #include "base/observer_list.h" +#include "base/supports_user_data.h" #include "base/types/pass_key.h" #include "build/build_config.h" #include "third_party/skia/include/core/SkPath.h" @@ -289,7 +290,8 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, public ui::EventTarget, public ui::EventHandler, public ui::PropertyHandler, - public ui::metadata::MetaDataProvider { + public ui::metadata::MetaDataProvider, + public base::SupportsUserData { // Do not remove this macro! // The macro is maintained by the memory safety team. ADVANCED_MEMORY_SAFETY_CHECKS(); @@ -609,7 +611,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Return the preferred height for a specific width. It is a helper function // of GetPreferredSize(SizeBounds(w, SizeBound())).height(). - int GetHeightForWidth(int w) const; + virtual int GetHeightForWidth(int w) const; // Returns a bound on the available space for a child view, for example, in // case the child view wants to play an animation that would cause it to