From 3458a5c8320d3db39b6fbb88ee31cea4d551ca20 Mon Sep 17 00:00:00 2001
From: "sky@chromium.org"
 <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Mon, 18 May 2009 16:16:40 +0000
Subject: Makes chrome_menu able to compile of Linux (the header that is). I'm
 going to do some major surgery to chrome_menu to get the rest compiling on
 linux.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/115431

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16281 0039d316-1c4b-4281-b951-d872f2087c98
---
 views/controls/menu/chrome_menu.cc | 56 ++++++++++++++++++++++----------------
 views/controls/menu/chrome_menu.h  | 35 ++++++++++++++----------
 2 files changed, 53 insertions(+), 38 deletions(-)

(limited to 'views/controls/menu')

diff --git a/views/controls/menu/chrome_menu.cc b/views/controls/menu/chrome_menu.cc
index 264c8b7..6e5da26 100644
--- a/views/controls/menu/chrome_menu.cc
+++ b/views/controls/menu/chrome_menu.cc
@@ -209,6 +209,8 @@ static void ScrollToVisible(View* view) {
   view->ScrollRectToVisible(0, 0, view->width(), view->height());
 }
 
+}  // namespace
+
 // MenuScrollTask --------------------------------------------------------------
 
 // MenuScrollTask is used when the SubmenuView does not all fit on screen and
@@ -216,7 +218,7 @@ static void ScrollToVisible(View* view) {
 // itself with a RepeatingTimer. When Run is invoked MenuScrollTask scrolls
 // appropriately.
 
-class MenuScrollTask {
+class MenuController::MenuScrollTask {
  public:
   MenuScrollTask() : submenu_(NULL) {
     pixels_per_second_ = pref_menu_height * 20;
@@ -292,6 +294,8 @@ class MenuScrollTask {
   DISALLOW_COPY_AND_ASSIGN(MenuScrollTask);
 };
 
+namespace {
+
 // MenuScrollButton ------------------------------------------------------------
 
 // MenuScrollButton is used for the scroll buttons when not all menu items fit
@@ -409,6 +413,8 @@ class MenuScrollView : public View {
   DISALLOW_COPY_AND_ASSIGN(MenuScrollView);
 };
 
+}  // namespace
+
 // MenuScrollViewContainer -----------------------------------------------------
 
 // MenuScrollViewContainer contains the SubmenuView (through a MenuScrollView)
@@ -494,6 +500,8 @@ class MenuScrollViewContainer : public View {
   DISALLOW_COPY_AND_ASSIGN(MenuScrollViewContainer);
 };
 
+namespace {
+
 // MenuSeparator ---------------------------------------------------------------
 
 // Renders a separator.
@@ -642,6 +650,8 @@ class MenuHostRootView : public RootView {
   DISALLOW_COPY_AND_ASSIGN(MenuHostRootView);
 };
 
+}  // namespace
+
 // MenuHost ------------------------------------------------------------------
 
 // MenuHost is the window responsible for showing a single menu.
@@ -763,6 +773,8 @@ class MenuHost : public WidgetWin {
   DISALLOW_COPY_AND_ASSIGN(MenuHost);
 };
 
+namespace {
+
 // EmptyMenuMenuItem ---------------------------------------------------------
 
 // EmptyMenuMenuItem is used when a menu has no menu items. EmptyMenuMenuItem
@@ -1417,10 +1429,8 @@ void MenuItemView::RemoveEmptyMenus() {
   }
 }
 
-void MenuItemView::AdjustBoundsForRTLUI(RECT* rect) const {
-  gfx::Rect mirrored_rect(*rect);
-  mirrored_rect.set_x(MirroredLeftPointForRect(mirrored_rect));
-  *rect = mirrored_rect.ToRECT();
+void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const {
+  rect->set_x(MirroredLeftPointForRect(*rect));
 }
 
 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
@@ -1433,21 +1443,22 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
 
   // The gutter is rendered before the background.
   if (render_gutter && !for_drag) {
-    RECT gutter_bounds = { label_start - kGutterToLabel - gutter_width, 0, 0,
-                           height() };
-    gutter_bounds.right = gutter_bounds.left + gutter_width;
+    gfx::Rect gutter_bounds(label_start - kGutterToLabel - gutter_width, 0,
+                            gutter_width, height());
     AdjustBoundsForRTLUI(&gutter_bounds);
+    RECT gutter_rect = gutter_bounds.ToRECT();
     NativeTheme::instance()->PaintMenuGutter(dc, MENU_POPUPGUTTER, MPI_NORMAL,
-                                             &gutter_bounds);
+                                             &gutter_rect);
   }
 
   // Render the background.
   if (!for_drag) {
-    RECT item_bounds = { 0, 0, width(), height() };
+    gfx::Rect item_bounds(0, 0, width(), height());
     AdjustBoundsForRTLUI(&item_bounds);
+    RECT item_rect = item_bounds.ToRECT();
     NativeTheme::instance()->PaintMenuItemBackground(
         NativeTheme::MENU, dc, MENU_POPUPITEM, state, render_selection,
-        &item_bounds);
+        &item_rect);
   }
 
   int icon_x = kItemLeftMargin;
@@ -1460,21 +1471,22 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
 
   if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) {
     // Draw the check background.
-    RECT check_bg_bounds = { 0, 0, icon_x + icon_width, height() };
+    gfx::Rect check_bg_bounds(0, 0, icon_x + icon_width, height());
     const int bg_state = IsEnabled() ? MCB_NORMAL : MCB_DISABLED;
     AdjustBoundsForRTLUI(&check_bg_bounds);
+    RECT check_bg_rect = check_bg_bounds.ToRECT();
     NativeTheme::instance()->PaintMenuCheckBackground(
         NativeTheme::MENU, dc, MENU_POPUPCHECKBACKGROUND, bg_state,
-        &check_bg_bounds);
+        &check_bg_rect);
 
     // And the check.
-    RECT check_bounds = { icon_x, icon_y, icon_x + icon_width,
-                          icon_y + icon_height };
+    gfx::Rect check_bounds(icon_x, icon_y, icon_width, icon_height);
     const int check_state = IsEnabled() ? MC_CHECKMARKNORMAL :
                                           MC_CHECKMARKDISABLED;
     AdjustBoundsForRTLUI(&check_bounds);
+    RECT check_rect = check_bounds.ToRECT();
     NativeTheme::instance()->PaintMenuCheck(
-        NativeTheme::MENU, dc, MENU_POPUPCHECK, check_state, &check_bounds,
+        NativeTheme::MENU, dc, MENU_POPUPCHECK, check_state, &check_rect,
         render_selection);
   }
 
@@ -1517,13 +1529,8 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
 
   if (HasSubmenu()) {
     int state_id = IsEnabled() ? MSM_NORMAL : MSM_DISABLED;
-    RECT arrow_bounds = {
-        this->width() - item_right_margin + kLabelToArrowPadding,
-        0,
-        0,
-        height()
-    };
-    arrow_bounds.right = arrow_bounds.left + arrow_width;
+    gfx::Rect arrow_bounds(this->width() - item_right_margin + kLabelToArrowPadding,
+                           0, arrow_width, height());
     AdjustBoundsForRTLUI(&arrow_bounds);
 
     // If our sub menus open from right to left (which is the case when the
@@ -1535,8 +1542,9 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
     else
       arrow_direction = NativeTheme::RIGHT_POINTING_ARROW;
 
+    RECT arrow_rect = arrow_bounds.ToRECT();
     NativeTheme::instance()->PaintMenuArrow(
-        NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_bounds,
+        NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect,
         arrow_direction, render_selection);
   }
   canvas->endPlatformPaint();
diff --git a/views/controls/menu/chrome_menu.h b/views/controls/menu/chrome_menu.h
index 8ff9ec0..a01311e 100644
--- a/views/controls/menu/chrome_menu.h
+++ b/views/controls/menu/chrome_menu.h
@@ -10,6 +10,7 @@
 
 #include "app/drag_drop_types.h"
 #include "app/gfx/font.h"
+#include "base/gfx/native_widget_types.h"
 #include "base/gfx/point.h"
 #include "base/gfx/rect.h"
 #include "base/message_loop.h"
@@ -21,16 +22,14 @@
 
 namespace views {
 
-class WidgetWin;
 class MenuController;
+class MenuHost;
 class MenuItemView;
+class MenuScrollViewContainer;
 class SubmenuView;
 
 namespace {
-class MenuHost;
 class MenuHostRootView;
-class MenuScrollTask;
-class MenuScrollViewContainer;
 }
 
 // MenuDelegate --------------------------------------------------------------
@@ -238,11 +237,11 @@ class MenuItemView : public View {
   // a rectangle, which is used to position the menu. |has_mnemonics| indicates
   // whether the items have mnemonics. Mnemonics are identified by way of the
   // character following the '&'.
-  void RunMenuAt(HWND parent,
+  void RunMenuAt(gfx::NativeView parent,
                  const gfx::Rect& bounds,
                  AnchorPosition anchor,
                  bool has_mnemonics);
-  void RunMenuForDropAt(HWND parent,
+  void RunMenuForDropAt(gfx::NativeView parent,
                         const gfx::Rect& bounds,
                         AnchorPosition anchor);
 
@@ -417,7 +416,7 @@ class MenuItemView : public View {
 
   // Given bounds within our View, this helper routine mirrors the bounds if
   // necessary.
-  void AdjustBoundsForRTLUI(RECT* rect) const;
+  void AdjustBoundsForRTLUI(gfx::Rect* rect) const;
 
   // Actual paint implementation. If for_drag is true, portions of the menu
   // are not rendered.
@@ -534,7 +533,7 @@ class SubmenuView : public View {
 
   // Shows the menu at the specified location. Coordinates are in screen
   // coordinates. max_width gives the max width the view should be.
-  void ShowAt(HWND parent, const gfx::Rect& bounds, bool do_capture);
+  void ShowAt(gfx::NativeView parent, const gfx::Rect& bounds, bool do_capture);
 
   // Closes the menu, destroying the host.
   void Close();
@@ -614,11 +613,15 @@ class SubmenuView : public View {
 // All relevant events are forwarded to the MenuController from SubmenuView
 // and MenuHost.
 
-class MenuController : public MessageLoopForUI::Dispatcher {
+class MenuController
+#if defined(OS_WIN)
+    : public MessageLoopForUI::Dispatcher {
+#else
+    {
+#endif
  public:
   friend class MenuHostRootView;
   friend class MenuItemView;
-  friend class MenuScrollTask;
 
   // If a menu is currently active, this returns the controller for it.
   static MenuController* GetActiveInstance();
@@ -626,7 +629,7 @@ class MenuController : public MessageLoopForUI::Dispatcher {
   // Runs the menu at the specified location. If the menu was configured to
   // block, the selected item is returned. If the menu does not block this
   // returns NULL immediately.
-  MenuItemView* Run(HWND parent,
+  MenuItemView* Run(gfx::NativeView parent,
                     MenuItemView* root,
                     const gfx::Rect& bounds,
                     MenuItemView::AnchorPosition position,
@@ -674,6 +677,8 @@ class MenuController : public MessageLoopForUI::Dispatcher {
   void OnDragExitedScrollButton(SubmenuView* source);
 
  private:
+  class MenuScrollTask;
+
   // Tracks selection information.
   struct State {
     State() : item(NULL), submenu_open(false) {}
@@ -730,6 +735,7 @@ class MenuController : public MessageLoopForUI::Dispatcher {
   // Sets the active MenuController.
   static void SetActiveInstance(MenuController* controller);
 
+#if defined(OS_WIN)
   // Dispatcher method. This returns true if the menu was canceled, or
   // if the message is such that the menu should be closed.
   virtual bool Dispatch(const MSG& msg);
@@ -739,6 +745,7 @@ class MenuController : public MessageLoopForUI::Dispatcher {
   // pressed, or a matching mnemonic was found) the message loop returns.
   bool OnKeyDown(const MSG& msg);
   bool OnChar(const MSG& msg);
+#endif
 
   // Creates a MenuController. If blocking is true, Run blocks the caller
   explicit MenuController(bool blocking);
@@ -842,7 +849,7 @@ class MenuController : public MessageLoopForUI::Dispatcher {
 
   // Returns true if window is the window used to show item, or any of
   // items ancestors.
-  bool IsMenuWindow(MenuItemView* item, HWND window);
+  bool IsMenuWindow(MenuItemView* item, gfx::NativeWindow window);
 
   // Selects by mnemonic, and if that doesn't work tries the first character of
   // the title. Returns true if a match was selected and the menu should exit.
@@ -918,7 +925,7 @@ class MenuController : public MessageLoopForUI::Dispatcher {
   MenuDelegate::DropPosition drop_position_;
 
   // Owner of child windows.
-  HWND owner_;
+  gfx::NativeWindow owner_;
 
   // Indicates a possible drag operation.
   bool possible_drag_;
@@ -941,7 +948,7 @@ class MenuController : public MessageLoopForUI::Dispatcher {
   // underway.
   scoped_ptr<MenuScrollTask> scroll_task_;
 
-  DISALLOW_EVIL_CONSTRUCTORS(MenuController);
+  DISALLOW_COPY_AND_ASSIGN(MenuController);
 };
 
 }  // namespace views
-- 
cgit v1.1