summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-23 17:01:55 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-23 17:01:55 +0000
commit1a2490c3e50dc17220981af077c005095af3606c (patch)
tree8e5a14c8cb6c2a13cbabb934e8b40c16c4a03c79 /views
parent9486d9305f26d3ecb3b7d44029c756254e75b1f2 (diff)
downloadchromium_src-1a2490c3e50dc17220981af077c005095af3606c.zip
chromium_src-1a2490c3e50dc17220981af077c005095af3606c.tar.gz
chromium_src-1a2490c3e50dc17220981af077c005095af3606c.tar.bz2
views: Pull out ContextMenuController class into its own header file.
BUG=72040 TEST=None R=ben@chromium.org,sky@chromium.org Review URL: http://codereview.chromium.org/7238006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/context_menu_controller.h45
-rw-r--r--views/controls/button/custom_button.cc2
-rw-r--r--views/controls/native_control.cc2
-rw-r--r--views/controls/native_control_win.cc2
-rw-r--r--views/controls/scrollbar/bitmap_scroll_bar.cc8
-rw-r--r--views/controls/scrollbar/bitmap_scroll_bar.h1
-rw-r--r--views/controls/textfield/native_textfield_views.cc2
-rw-r--r--views/controls/textfield/native_textfield_views.h1
-rw-r--r--views/controls/tree/tree_view.cc2
-rw-r--r--views/view.cc5
-rw-r--r--views/view.h36
-rw-r--r--views/views.gyp1
12 files changed, 63 insertions, 44 deletions
diff --git a/views/context_menu_controller.h b/views/context_menu_controller.h
new file mode 100644
index 0000000..d65bb1a
--- /dev/null
+++ b/views/context_menu_controller.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef VIEWS_CONTEXT_MENU_CONTROLLER_H_
+#define VIEWS_CONTEXT_MENU_CONTROLLER_H_
+#pragma once
+
+namespace gfx {
+class Point;
+}
+
+namespace views {
+class View;
+
+// ContextMenuController is responsible for showing the context menu for a
+// View. To use a ContextMenuController invoke set_context_menu_controller on a
+// View. When the appropriate user gesture occurs ShowContextMenu is invoked
+// on the ContextMenuController.
+//
+// Setting a ContextMenuController on a view makes the view process mouse
+// events.
+//
+// It is up to subclasses that do their own mouse processing to invoke
+// the appropriate ContextMenuController method, typically by invoking super's
+// implementation for mouse processing.
+class ContextMenuController {
+ public:
+ // Invoked to show the context menu for the source view. If |is_mouse_gesture|
+ // is true, |p| is the location of the mouse. If |is_mouse_gesture| is false,
+ // this method was not invoked by a mouse gesture and |p| is the recommended
+ // location to show the menu at.
+ //
+ // |p| is in screen coordinates.
+ virtual void ShowContextMenuForView(View* source,
+ const gfx::Point& p,
+ bool is_mouse_gesture) = 0;
+
+ protected:
+ virtual ~ContextMenuController() {}
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTEXT_MENU_CONTROLLER_H_
diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc
index dab4e32..8e6e09c 100644
--- a/views/controls/button/custom_button.cc
+++ b/views/controls/button/custom_button.cc
@@ -207,7 +207,7 @@ bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) {
}
void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) {
- if (!GetContextMenuController())
+ if (!context_menu_controller())
return;
// We're about to show the context menu. Showing the context menu likely means
diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc
index 03fc301..9958be2 100644
--- a/views/controls/native_control.cc
+++ b/views/controls/native_control.cc
@@ -267,7 +267,7 @@ void NativeControl::Layout() {
}
void NativeControl::OnContextMenu(const POINT& location) {
- if (!GetContextMenuController())
+ if (!context_menu_controller())
return;
if (location.x == -1 && location.y == -1)
diff --git a/views/controls/native_control_win.cc b/views/controls/native_control_win.cc
index 9630bd6..9d1af49 100644
--- a/views/controls/native_control_win.cc
+++ b/views/controls/native_control_win.cc
@@ -122,7 +122,7 @@ void NativeControlWin::OnFocus() {
// NativeControlWin, protected:
void NativeControlWin::ShowContextMenu(const gfx::Point& location) {
- if (!GetContextMenuController())
+ if (!context_menu_controller())
return;
if (location.x() == -1 && location.y() == -1)
diff --git a/views/controls/scrollbar/bitmap_scroll_bar.cc b/views/controls/scrollbar/bitmap_scroll_bar.cc
index 2785987..ca35cbe 100644
--- a/views/controls/scrollbar/bitmap_scroll_bar.cc
+++ b/views/controls/scrollbar/bitmap_scroll_bar.cc
@@ -299,10 +299,10 @@ BitmapScrollBar::BitmapScrollBar(bool horizontal, bool show_scroll_buttons)
AddChildView(next_button_);
AddChildView(thumb_);
- SetContextMenuController(this);
- prev_button_->SetContextMenuController(this);
- next_button_->SetContextMenuController(this);
- thumb_->SetContextMenuController(this);
+ set_context_menu_controller(this);
+ prev_button_->set_context_menu_controller(this);
+ next_button_->set_context_menu_controller(this);
+ thumb_->set_context_menu_controller(this);
}
gfx::Rect BitmapScrollBar::GetTrackBounds() const {
diff --git a/views/controls/scrollbar/bitmap_scroll_bar.h b/views/controls/scrollbar/bitmap_scroll_bar.h
index 833a045..ce072bf 100644
--- a/views/controls/scrollbar/bitmap_scroll_bar.h
+++ b/views/controls/scrollbar/bitmap_scroll_bar.h
@@ -6,6 +6,7 @@
#define VIEWS_CONTROLS_SCROLLBAR_BITMAP_SCROLL_BAR_H_
#pragma once
+#include "views/context_menu_controller.h"
#include "views/controls/button/image_button.h"
#include "views/controls/menu/menu.h"
#include "views/controls/scrollbar/scroll_bar.h"
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index 472a5cb..31c7e4d 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -79,7 +79,7 @@ NativeTextfieldViews::NativeTextfieldViews(Textfield* parent)
// Lowercase is not supported.
DCHECK_NE(parent->style(), Textfield::STYLE_LOWERCASE);
- SetContextMenuController(this);
+ set_context_menu_controller(this);
set_drag_controller(this);
}
diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h
index 4da13dd..d425472 100644
--- a/views/controls/textfield/native_textfield_views.h
+++ b/views/controls/textfield/native_textfield_views.h
@@ -11,6 +11,7 @@
#include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/font.h"
#include "views/border.h"
+#include "views/context_menu_controller.h"
#include "views/controls/textfield/native_textfield_wrapper.h"
#include "views/controls/textfield/textfield_views_model.h"
#include "views/drag_controller.h"
diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc
index fb10f49..b71bf5f 100644
--- a/views/controls/tree/tree_view.cc
+++ b/views/controls/tree/tree_view.cc
@@ -488,7 +488,7 @@ bool TreeView::OnKeyDown(ui::KeyboardCode virtual_key_code) {
}
void TreeView::OnContextMenu(const POINT& location) {
- if (!GetContextMenuController())
+ if (!context_menu_controller())
return;
if (location.x == -1 && location.y == -1) {
diff --git a/views/view.cc b/views/view.cc
index ad6609f..c67aac2 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -19,6 +19,7 @@
#include "ui/gfx/path.h"
#include "ui/gfx/transform.h"
#include "views/background.h"
+#include "views/context_menu_controller.h"
#include "views/drag_controller.h"
#include "views/layout/layout_manager.h"
#include "views/views_delegate.h"
@@ -998,10 +999,6 @@ bool View::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc) {
// Context menus ---------------------------------------------------------------
-void View::SetContextMenuController(ContextMenuController* menu_controller) {
- context_menu_controller_ = menu_controller;
-}
-
void View::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) {
if (!context_menu_controller_)
return;
diff --git a/views/view.h b/views/view.h
index 8b32bb6..544c705 100644
--- a/views/view.h
+++ b/views/view.h
@@ -49,6 +49,7 @@ namespace views {
class Background;
class Border;
+class ContextMenuController;
class DragController;
class FocusManager;
class FocusTraversable;
@@ -62,34 +63,6 @@ namespace internal {
class RootView;
}
-// ContextMenuController is responsible for showing the context menu for a
-// View. To use a ContextMenuController invoke SetContextMenuController on a
-// View. When the appropriate user gesture occurs ShowContextMenu is invoked
-// on the ContextMenuController.
-//
-// Setting a ContextMenuController on a view makes the view process mouse
-// events.
-//
-// It is up to subclasses that do their own mouse processing to invoke
-// the appropriate ContextMenuController method, typically by invoking super's
-// implementation for mouse processing.
-//
-class ContextMenuController {
- public:
- // Invoked to show the context menu for the source view. If |is_mouse_gesture|
- // is true, |p| is the location of the mouse. If |is_mouse_gesture| is false,
- // this method was not invoked by a mouse gesture and |p| is the recommended
- // location to show the menu at.
- //
- // |p| is in screen coordinates.
- virtual void ShowContextMenuForView(View* source,
- const gfx::Point& p,
- bool is_mouse_gesture) = 0;
-
- protected:
- virtual ~ContextMenuController() {}
-};
-
/////////////////////////////////////////////////////////////////////////////
//
// View class
@@ -119,7 +92,6 @@ class View : public AcceleratorTarget {
public:
typedef std::vector<View*> Views;
-
// TO BE MOVED ---------------------------------------------------------------
// TODO(beng): These methods are to be moved to other files/classes.
@@ -749,10 +721,12 @@ class View : public AcceleratorTarget {
// Sets the ContextMenuController. Setting this to non-null makes the View
// process mouse events.
- void SetContextMenuController(ContextMenuController* menu_controller);
- ContextMenuController* GetContextMenuController() {
+ ContextMenuController* context_menu_controller() {
return context_menu_controller_;
}
+ void set_context_menu_controller(ContextMenuController* menu_controller) {
+ context_menu_controller_ = menu_controller;
+ }
// Provides default implementation for context menu handling. The default
// implementation calls the ShowContextMenu of the current
diff --git a/views/views.gyp b/views/views.gyp
index 772dbf3..6a295cf 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -84,6 +84,7 @@
'background.h',
'border.cc',
'border.h',
+ 'context_menu_controller.h',
'controls/button/button.cc',
'controls/button/button.h',
'controls/button/button_dropdown.cc',