diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 03:20:55 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-09 03:20:55 +0000 |
commit | 2b9277dc6dd0ed8426078b3afb48cd1383df8fbe (patch) | |
tree | 6cf736441cc877fe4fff0968bcb2f669e441f025 /views | |
parent | 31cc2fdd5f43c4c6a0c0ebe0679458ecb3ba1593 (diff) | |
download | chromium_src-2b9277dc6dd0ed8426078b3afb48cd1383df8fbe.zip chromium_src-2b9277dc6dd0ed8426078b3afb48cd1383df8fbe.tar.gz chromium_src-2b9277dc6dd0ed8426078b3afb48cd1383df8fbe.tar.bz2 |
Wires up drag and drop for bookmark menus and cleans up a couple of
minor painting issues.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/199050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25701 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/menu/menu_config_gtk.cc | 1 | ||||
-rw-r--r-- | views/controls/menu/menu_controller.cc | 30 | ||||
-rw-r--r-- | views/controls/menu/menu_controller.h | 6 | ||||
-rw-r--r-- | views/controls/menu/menu_delegate.h | 18 | ||||
-rw-r--r-- | views/controls/menu/menu_scroll_view_container.cc | 15 | ||||
-rw-r--r-- | views/controls/menu/menu_separator_gtk.cc | 7 | ||||
-rw-r--r-- | views/controls/menu/submenu_view.cc | 13 | ||||
-rw-r--r-- | views/controls/menu/submenu_view.h | 4 |
8 files changed, 67 insertions, 27 deletions
diff --git a/views/controls/menu/menu_config_gtk.cc b/views/controls/menu/menu_config_gtk.cc index acb77ff..84c9aa6 100644 --- a/views/controls/menu/menu_config_gtk.cc +++ b/views/controls/menu/menu_config_gtk.cc @@ -12,7 +12,6 @@ namespace views { // static MenuConfig* MenuConfig::Create() { - // TODO: decide what we want this to look like. MenuConfig* config = new MenuConfig(); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); config->font = rb.GetFont(ResourceBundle::BaseFont); diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 8016868..3df3030 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -12,6 +12,7 @@ #include "views/controls/menu/menu_scroll_view_container.h" #include "views/controls/menu/submenu_view.h" #include "views/drag_utils.h" +#include "views/screen.h" #include "views/view_constants.h" #include "views/widget/root_view.h" #include "views/widget/widget.h" @@ -176,22 +177,10 @@ MenuItemView* MenuController::Run(gfx::NativeView parent, pending_state_.anchor = position; owner_ = parent; - // TODO: push this into Screen. // Calculate the bounds of the monitor we'll show menus on. Do this once to // avoid repeated system queries for the info. -#if defined(OS_WIN) - POINT initial_loc = { bounds.x(), bounds.y() }; - HMONITOR monitor = MonitorFromPoint(initial_loc, MONITOR_DEFAULTTONEAREST); - if (monitor) { - MONITORINFO mi = {0}; - mi.cbSize = sizeof(mi); - GetMonitorInfo(monitor, &mi); - // Menus appear over the taskbar. - pending_state_.monitor_bounds = gfx::Rect(mi.rcMonitor); - } -#else - NOTIMPLEMENTED(); -#endif + pending_state_.monitor_bounds = Screen::GetMonitorAreaNearestPoint( + bounds.origin()); // Set the selection, which opens the initial menu. SetSelection(root, true, true); @@ -496,6 +485,19 @@ void MenuController::OnMouseEntered(SubmenuView* source, // do anything here. } +bool MenuController::GetDropFormats( + SubmenuView* source, + int* formats, + std::set<OSExchangeData::CustomFormat>* custom_formats) { + return source->GetMenuItem()->GetDelegate()->GetDropFormats( + source->GetMenuItem(), formats, custom_formats); +} + +bool MenuController::AreDropTypesRequired(SubmenuView* source) { + return source->GetMenuItem()->GetDelegate()->AreDropTypesRequired( + source->GetMenuItem()); +} + bool MenuController::CanDrop(SubmenuView* source, const OSExchangeData& data) { return source->GetMenuItem()->GetDelegate()->CanDrop(source->GetMenuItem(), data); diff --git a/views/controls/menu/menu_controller.h b/views/controls/menu/menu_controller.h index ac84af5..eb6e87e 100644 --- a/views/controls/menu/menu_controller.h +++ b/views/controls/menu/menu_controller.h @@ -8,6 +8,7 @@ #include "build/build_config.h" #include <list> +#include <set> #include <vector> #include "base/message_loop.h" @@ -79,6 +80,11 @@ class MenuController : public MessageLoopForUI::Dispatcher { void OnMouseReleased(SubmenuView* source, const MouseEvent& event); void OnMouseMoved(SubmenuView* source, const MouseEvent& event); void OnMouseEntered(SubmenuView* source, const MouseEvent& event); + bool GetDropFormats( + SubmenuView* source, + int* formats, + std::set<OSExchangeData::CustomFormat>* custom_formats); + bool AreDropTypesRequired(SubmenuView* source); bool CanDrop(SubmenuView* source, const OSExchangeData& data); void OnDragEntered(SubmenuView* source, const DropTargetEvent& event); int OnDragUpdated(SubmenuView* source, const DropTargetEvent& event); diff --git a/views/controls/menu/menu_delegate.h b/views/controls/menu/menu_delegate.h index 5de7c06..ec66a4f 100644 --- a/views/controls/menu/menu_delegate.h +++ b/views/controls/menu/menu_delegate.h @@ -5,15 +5,15 @@ #ifndef VIEWS_CONTROLS_MENU_MENU_DELEGATE_H_ #define VIEWS_CONTROLS_MENU_MENU_DELEGATE_H_ +#include <set> #include <string> #include "app/drag_drop_types.h" +#include "app/os_exchange_data.h" #include "base/logging.h" #include "views/controls/menu/controller.h" #include "views/event.h" -class OSExchangeData; - namespace views { class DropTargetEvent; @@ -109,11 +109,25 @@ class MenuDelegate : Controller { // Where A has a submenu with children B and C. This is ONLY invoked for // A, not B and C. // + // To restrict which children can be dropped on override GetDropOperation. virtual bool CanDrop(MenuItemView* menu, const OSExchangeData& data) { return false; } + // See view for a description of this method. + virtual bool GetDropFormats( + MenuItemView* menu, + int* formats, + std::set<OSExchangeData::CustomFormat>* custom_formats) { + return false; + } + + // See view for a description of this method. + virtual bool AreDropTypesRequired(MenuItemView* menu) { + return false; + } + // Returns the drop operation for the specified target menu item. This is // only invoked if CanDrop returned true for the parent menu. position // is set based on the location of the mouse, reset to specify a different diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc index b50e926..54bfbdc 100644 --- a/views/controls/menu/menu_scroll_view_container.cc +++ b/views/controls/menu/menu_scroll_view_container.cc @@ -79,8 +79,9 @@ class MenuScrollButton : public View { } virtual void Paint(gfx::Canvas* canvas) { -#if defined(OS_WIN) const MenuConfig& config = MenuConfig::instance(); + +#if defined(OS_WIN) HDC dc = canvas->beginPlatformPaint(); // The background. @@ -88,6 +89,12 @@ class MenuScrollButton : public View { NativeTheme::instance()->PaintMenuItemBackground( NativeTheme::MENU, dc, MENU_POPUPITEM, MPI_NORMAL, false, &item_bounds); + canvas->endPlatformPaint(); + + SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT); +#else + SkColor arrow_color = SK_ColorBLACK; +#endif // Then the arrow. int x = width() / 2; @@ -97,14 +104,8 @@ class MenuScrollButton : public View { delta_y = -1; y += config.scroll_arrow_height; } - SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT); for (int i = 0; i < config.scroll_arrow_height; ++i, --x, y += delta_y) canvas->FillRectInt(arrow_color, x, y, (i * 2) + 1, 1); - - canvas->endPlatformPaint(); -#else - NOTIMPLEMENTED(); -#endif } private: diff --git a/views/controls/menu/menu_separator_gtk.cc b/views/controls/menu/menu_separator_gtk.cc index fdb5e8f..d0b7fba 100644 --- a/views/controls/menu/menu_separator_gtk.cc +++ b/views/controls/menu/menu_separator_gtk.cc @@ -4,13 +4,16 @@ #include "views/controls/menu/menu_separator.h" -#include "base/logging.h" +#include "app/gfx/canvas.h" +#include "third_party/skia/include/core/SkColor.h" #include "views/controls/menu/menu_config.h" namespace views { +static const SkColor kSeparatorColor = SkColorSetARGB(50, 00, 00, 00); + void MenuSeparator::Paint(gfx::Canvas* canvas) { - NOTIMPLEMENTED(); + canvas->DrawLineInt(kSeparatorColor, 0, height() / 2, width(), height() / 2); } gfx::Size MenuSeparator::GetPreferredSize() { diff --git a/views/controls/menu/submenu_view.cc b/views/controls/menu/submenu_view.cc index 46580c0..36495c9 100644 --- a/views/controls/menu/submenu_view.cc +++ b/views/controls/menu/submenu_view.cc @@ -112,7 +112,18 @@ void SubmenuView::PaintChildren(gfx::Canvas* canvas) { PaintDropIndicator(canvas, drop_item_, drop_position_); } -// TODO(sky): need to add support for new dnd methods for Linux. +bool SubmenuView::GetDropFormats( + int* formats, + std::set<OSExchangeData::CustomFormat>* custom_formats) { + DCHECK(GetMenuItem()->GetMenuController()); + return GetMenuItem()->GetMenuController()->GetDropFormats(this, formats, + custom_formats); +} + +bool SubmenuView::AreDropTypesRequired() { + DCHECK(GetMenuItem()->GetMenuController()); + return GetMenuItem()->GetMenuController()->AreDropTypesRequired(this); +} bool SubmenuView::CanDrop(const OSExchangeData& data) { DCHECK(GetMenuItem()->GetMenuController()); diff --git a/views/controls/menu/submenu_view.h b/views/controls/menu/submenu_view.h index 5547b8e..c8bce96 100644 --- a/views/controls/menu/submenu_view.h +++ b/views/controls/menu/submenu_view.h @@ -56,6 +56,10 @@ class SubmenuView : public View { void PaintChildren(gfx::Canvas* canvas); // Drag and drop methods. These are forwarded to the MenuController. + virtual bool GetDropFormats( + int* formats, + std::set<OSExchangeData::CustomFormat>* custom_formats); + virtual bool AreDropTypesRequired(); virtual bool CanDrop(const OSExchangeData& data); virtual void OnDragEntered(const DropTargetEvent& event); virtual int OnDragUpdated(const DropTargetEvent& event); |