Commit b53d14b4 authored by Xiao Yang's avatar Xiao Yang Committed by Commit Bot

Add API to RenderViewContextMenuObserver

1. Add OnMenuClosed to notify observers when context menu is dismissed.
2. Add OnContextMenuShown to notify observers when context menu is
shown.

Bug: 1020004
Change-Id: I61f8c44edd909f3ba5e0566cb60cb79b59433091
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055357Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Commit-Queue: Xiao Yang <yanxiao@google.com>
Cr-Commit-Position: refs/heads/master@{#743369}
parent bfb35d53
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/controls/menu/menu_host.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
using content::WebContents; using content::WebContents;
...@@ -298,6 +301,15 @@ void RenderViewContextMenuViews::Show() { ...@@ -298,6 +301,15 @@ void RenderViewContextMenuViews::Show() {
// the context menu is being displayed. // the context menu is being displayed.
base::MessageLoopCurrent::ScopedNestableTaskAllower allow; base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
RunMenuAt(top_level_widget, screen_point, params().source_type); RunMenuAt(top_level_widget, screen_point, params().source_type);
for (auto& observer : observers_) {
observer.OnContextMenuShown(
params_, static_cast<ToolkitDelegateViews*>(toolkit_delegate())
->menu_view()
->GetSubmenu()
->host()
->GetWindowBoundsInScreen());
}
} }
views::Widget* RenderViewContextMenuViews::GetTopLevelWidget() { views::Widget* RenderViewContextMenuViews::GetTopLevelWidget() {
......
...@@ -413,6 +413,9 @@ void RenderViewContextMenuBase::MenuClosed(ui::SimpleMenuModel* source) { ...@@ -413,6 +413,9 @@ void RenderViewContextMenuBase::MenuClosed(ui::SimpleMenuModel* source) {
source_web_contents_->SetShowingContextMenu(false); source_web_contents_->SetShowingContextMenu(false);
source_web_contents_->NotifyContextMenuClosed(params_.custom_context); source_web_contents_->NotifyContextMenuClosed(params_.custom_context);
for (auto& observer : observers_) {
observer.OnMenuClosed();
}
} }
RenderFrameHost* RenderViewContextMenuBase::GetRenderFrameHost() { RenderFrameHost* RenderViewContextMenuBase::GetRenderFrameHost() {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ #ifndef COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_
#define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ #define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_
#include "ui/gfx/geometry/rect.h"
namespace content { namespace content {
struct ContextMenuParams; struct ContextMenuParams;
} }
...@@ -100,6 +102,11 @@ class RenderViewContextMenuObserver { ...@@ -100,6 +102,11 @@ class RenderViewContextMenuObserver {
// Called when a user selects the specified context-menu item. // Called when a user selects the specified context-menu item.
virtual void ExecuteCommand(int command_id) {} virtual void ExecuteCommand(int command_id) {}
virtual void OnMenuClosed() {}
virtual void OnContextMenuShown(const content::ContextMenuParams& params,
gfx::Rect bounds) {}
}; };
#endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_
...@@ -34,6 +34,7 @@ class ToolkitDelegateViews : public RenderViewContextMenuBase::ToolkitDelegate { ...@@ -34,6 +34,7 @@ class ToolkitDelegateViews : public RenderViewContextMenuBase::ToolkitDelegate {
void RunMenuAt(views::Widget* parent, void RunMenuAt(views::Widget* parent,
const gfx::Point& point, const gfx::Point& point,
ui::MenuSourceType type); ui::MenuSourceType type);
views::MenuItemView* menu_view() { return menu_view_; }
protected: protected:
// ToolkitDelegate: // ToolkitDelegate:
......
...@@ -168,6 +168,7 @@ class VIEWS_EXPORT SubmenuView : public View, ...@@ -168,6 +168,7 @@ class VIEWS_EXPORT SubmenuView : public View,
void set_resize_open_menu(bool resize_open_menu) { void set_resize_open_menu(bool resize_open_menu) {
resize_open_menu_ = resize_open_menu; resize_open_menu_ = resize_open_menu;
} }
MenuHost* host() { return host_; }
protected: protected:
// View method. Overridden to schedule a paint. We do this so that when // View method. Overridden to schedule a paint. We do this so that when
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment