| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/menu/menu_scroll_view_container.h" | 5 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <uxtheme.h> | 9 #include <uxtheme.h> |
| 10 #include <Vssym32.h> | 10 #include <Vssym32.h> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 class MenuScrollButton : public View { | 41 class MenuScrollButton : public View { |
| 42 public: | 42 public: |
| 43 MenuScrollButton(SubmenuView* host, bool is_up) | 43 MenuScrollButton(SubmenuView* host, bool is_up) |
| 44 : host_(host), | 44 : host_(host), |
| 45 is_up_(is_up), | 45 is_up_(is_up), |
| 46 // Make our height the same as that of other MenuItemViews. | 46 // Make our height the same as that of other MenuItemViews. |
| 47 pref_height_(MenuItemView::pref_menu_height()) { | 47 pref_height_(MenuItemView::pref_menu_height()) { |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual gfx::Size GetPreferredSize() { | 50 virtual gfx::Size GetPreferredSize() { |
| 51 return gfx::Size(MenuConfig::instance().scroll_arrow_height * 2 - 1, | 51 return gfx::Size( |
| 52 pref_height_); | 52 host_->GetMenuItem()->GetMenuConfig().scroll_arrow_height * 2 - 1, |
| 53 pref_height_); |
| 53 } | 54 } |
| 54 | 55 |
| 55 virtual bool CanDrop(const OSExchangeData& data) { | 56 virtual bool CanDrop(const OSExchangeData& data) { |
| 56 DCHECK(host_->GetMenuItem()->GetMenuController()); | 57 DCHECK(host_->GetMenuItem()->GetMenuController()); |
| 57 return true; // Always return true so that drop events are targeted to us. | 58 return true; // Always return true so that drop events are targeted to us. |
| 58 } | 59 } |
| 59 | 60 |
| 60 virtual void OnDragEntered(const ui::DropTargetEvent& event) { | 61 virtual void OnDragEntered(const ui::DropTargetEvent& event) { |
| 61 DCHECK(host_->GetMenuItem()->GetMenuController()); | 62 DCHECK(host_->GetMenuItem()->GetMenuController()); |
| 62 host_->GetMenuItem()->GetMenuController()->OnDragEnteredScrollButton( | 63 host_->GetMenuItem()->GetMenuController()->OnDragEnteredScrollButton( |
| 63 host_, is_up_); | 64 host_, is_up_); |
| 64 } | 65 } |
| 65 | 66 |
| 66 virtual int OnDragUpdated(const ui::DropTargetEvent& event) { | 67 virtual int OnDragUpdated(const ui::DropTargetEvent& event) { |
| 67 return ui::DragDropTypes::DRAG_NONE; | 68 return ui::DragDropTypes::DRAG_NONE; |
| 68 } | 69 } |
| 69 | 70 |
| 70 virtual void OnDragExited() { | 71 virtual void OnDragExited() { |
| 71 DCHECK(host_->GetMenuItem()->GetMenuController()); | 72 DCHECK(host_->GetMenuItem()->GetMenuController()); |
| 72 host_->GetMenuItem()->GetMenuController()->OnDragExitedScrollButton(host_); | 73 host_->GetMenuItem()->GetMenuController()->OnDragExitedScrollButton(host_); |
| 73 } | 74 } |
| 74 | 75 |
| 75 virtual int OnPerformDrop(const ui::DropTargetEvent& event) { | 76 virtual int OnPerformDrop(const ui::DropTargetEvent& event) { |
| 76 return ui::DragDropTypes::DRAG_NONE; | 77 return ui::DragDropTypes::DRAG_NONE; |
| 77 } | 78 } |
| 78 | 79 |
| 79 virtual void OnPaint(gfx::Canvas* canvas) { | 80 virtual void OnPaint(gfx::Canvas* canvas) { |
| 80 const MenuConfig& config = MenuConfig::instance(); | 81 const MenuConfig& config = host_->GetMenuItem()->GetMenuConfig(); |
| 81 | 82 |
| 82 // The background. | 83 // The background. |
| 83 gfx::Rect item_bounds(0, 0, width(), height()); | 84 gfx::Rect item_bounds(0, 0, width(), height()); |
| 84 NativeTheme::ExtraParams extra; | 85 NativeTheme::ExtraParams extra; |
| 85 extra.menu_item.is_selected = false; | 86 extra.menu_item.is_selected = false; |
| 86 NativeTheme::instance()->Paint(canvas->sk_canvas(), | 87 NativeTheme::instance()->Paint(canvas->sk_canvas(), |
| 87 NativeTheme::kMenuItemBackground, | 88 NativeTheme::kMenuItemBackground, |
| 88 NativeTheme::kNormal, item_bounds, extra); | 89 NativeTheme::kNormal, item_bounds, extra); |
| 89 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
| 90 SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT); | 91 SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 scroll_up_button_ = new MenuScrollButton(content_view, true); | 178 scroll_up_button_ = new MenuScrollButton(content_view, true); |
| 178 scroll_down_button_ = new MenuScrollButton(content_view, false); | 179 scroll_down_button_ = new MenuScrollButton(content_view, false); |
| 179 AddChildView(scroll_up_button_); | 180 AddChildView(scroll_up_button_); |
| 180 AddChildView(scroll_down_button_); | 181 AddChildView(scroll_down_button_); |
| 181 | 182 |
| 182 scroll_view_ = new MenuScrollView(content_view); | 183 scroll_view_ = new MenuScrollView(content_view); |
| 183 AddChildView(scroll_view_); | 184 AddChildView(scroll_view_); |
| 184 | 185 |
| 185 MenuDelegate* delegate = content_view_->GetMenuItem()->GetDelegate(); | 186 MenuDelegate* delegate = content_view_->GetMenuItem()->GetDelegate(); |
| 186 if (delegate) { | 187 if (delegate) { |
| 187 set_border(delegate->CreateMenuBorder()); | 188 Border* border = delegate->CreateMenuBorder(); |
| 189 if (!border) { |
| 190 const MenuConfig& menu_config = |
| 191 content_view_->GetMenuItem()->GetMenuConfig(); |
| 192 border = Border::CreateEmptyBorder( |
| 193 menu_config.submenu_vertical_margin_size, |
| 194 menu_config.submenu_horizontal_margin_size, |
| 195 menu_config.submenu_vertical_margin_size, |
| 196 menu_config.submenu_horizontal_margin_size); |
| 197 } |
| 198 set_border(border); |
| 199 |
| 188 set_background(delegate->CreateMenuBackground()); | 200 set_background(delegate->CreateMenuBackground()); |
| 189 } | 201 } |
| 190 } | 202 } |
| 191 | 203 |
| 192 void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { | 204 void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { |
| 193 if (background()) { | 205 if (background()) { |
| 194 View::OnPaintBackground(canvas); | 206 View::OnPaintBackground(canvas); |
| 195 return; | 207 return; |
| 196 } | 208 } |
| 197 | 209 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 267 |
| 256 void MenuScrollViewContainer::OnBoundsChanged( | 268 void MenuScrollViewContainer::OnBoundsChanged( |
| 257 const gfx::Rect& previous_bounds) { | 269 const gfx::Rect& previous_bounds) { |
| 258 gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); | 270 gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); |
| 259 scroll_up_button_->SetVisible(content_pref.height() > height()); | 271 scroll_up_button_->SetVisible(content_pref.height() > height()); |
| 260 scroll_down_button_->SetVisible(content_pref.height() > height()); | 272 scroll_down_button_->SetVisible(content_pref.height() > height()); |
| 261 Layout(); | 273 Layout(); |
| 262 } | 274 } |
| 263 | 275 |
| 264 } // namespace views | 276 } // namespace views |
| OLD | NEW |