| 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 #include "third_party/skia/include/core/SkPaint.h" | 7 #include "third_party/skia/include/core/SkPaint.h" |
| 8 #include "third_party/skia/include/core/SkPath.h" | 8 #include "third_party/skia/include/core/SkPath.h" |
| 9 #include "ui/accessibility/ax_view_state.h" | 9 #include "ui/accessibility/ax_view_state.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 class MenuScrollButton : public View { | 34 class MenuScrollButton : public View { |
| 35 public: | 35 public: |
| 36 MenuScrollButton(SubmenuView* host, bool is_up) | 36 MenuScrollButton(SubmenuView* host, bool is_up) |
| 37 : host_(host), | 37 : host_(host), |
| 38 is_up_(is_up), | 38 is_up_(is_up), |
| 39 // Make our height the same as that of other MenuItemViews. | 39 // Make our height the same as that of other MenuItemViews. |
| 40 pref_height_(MenuItemView::pref_menu_height()) { | 40 pref_height_(MenuItemView::pref_menu_height()) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 gfx::Size GetPreferredSize() const override { | 43 gfx::Size GetPreferredSize() const override { |
| 44 return gfx::Size( | 44 return gfx::Size(MenuConfig::instance().scroll_arrow_height * 2 - 1, |
| 45 host_->GetMenuItem()->GetMenuConfig().scroll_arrow_height * 2 - 1, | 45 pref_height_); |
| 46 pref_height_); | |
| 47 } | 46 } |
| 48 | 47 |
| 49 bool CanDrop(const OSExchangeData& data) override { | 48 bool CanDrop(const OSExchangeData& data) override { |
| 50 DCHECK(host_->GetMenuItem()->GetMenuController()); | 49 DCHECK(host_->GetMenuItem()->GetMenuController()); |
| 51 return true; // Always return true so that drop events are targeted to us. | 50 return true; // Always return true so that drop events are targeted to us. |
| 52 } | 51 } |
| 53 | 52 |
| 54 void OnDragEntered(const ui::DropTargetEvent& event) override { | 53 void OnDragEntered(const ui::DropTargetEvent& event) override { |
| 55 DCHECK(host_->GetMenuItem()->GetMenuController()); | 54 DCHECK(host_->GetMenuItem()->GetMenuController()); |
| 56 host_->GetMenuItem()->GetMenuController()->OnDragEnteredScrollButton( | 55 host_->GetMenuItem()->GetMenuController()->OnDragEnteredScrollButton( |
| 57 host_, is_up_); | 56 host_, is_up_); |
| 58 } | 57 } |
| 59 | 58 |
| 60 int OnDragUpdated(const ui::DropTargetEvent& event) override { | 59 int OnDragUpdated(const ui::DropTargetEvent& event) override { |
| 61 return ui::DragDropTypes::DRAG_NONE; | 60 return ui::DragDropTypes::DRAG_NONE; |
| 62 } | 61 } |
| 63 | 62 |
| 64 void OnDragExited() override { | 63 void OnDragExited() override { |
| 65 DCHECK(host_->GetMenuItem()->GetMenuController()); | 64 DCHECK(host_->GetMenuItem()->GetMenuController()); |
| 66 host_->GetMenuItem()->GetMenuController()->OnDragExitedScrollButton(host_); | 65 host_->GetMenuItem()->GetMenuController()->OnDragExitedScrollButton(host_); |
| 67 } | 66 } |
| 68 | 67 |
| 69 int OnPerformDrop(const ui::DropTargetEvent& event) override { | 68 int OnPerformDrop(const ui::DropTargetEvent& event) override { |
| 70 return ui::DragDropTypes::DRAG_NONE; | 69 return ui::DragDropTypes::DRAG_NONE; |
| 71 } | 70 } |
| 72 | 71 |
| 73 void OnPaint(gfx::Canvas* canvas) override { | 72 void OnPaint(gfx::Canvas* canvas) override { |
| 74 const MenuConfig& config = host_->GetMenuItem()->GetMenuConfig(); | 73 const MenuConfig& config = MenuConfig::instance(); |
| 75 | 74 |
| 76 // The background. | 75 // The background. |
| 77 gfx::Rect item_bounds(0, 0, width(), height()); | 76 gfx::Rect item_bounds(0, 0, width(), height()); |
| 78 NativeTheme::ExtraParams extra; | 77 NativeTheme::ExtraParams extra; |
| 79 extra.menu_item.is_selected = false; | 78 extra.menu_item.is_selected = false; |
| 80 GetNativeTheme()->Paint(canvas->sk_canvas(), | 79 GetNativeTheme()->Paint(canvas->sk_canvas(), |
| 81 NativeTheme::kMenuItemBackground, | 80 NativeTheme::kMenuItemBackground, |
| 82 NativeTheme::kNormal, item_bounds, extra); | 81 NativeTheme::kNormal, item_bounds, extra); |
| 83 | 82 |
| 84 // Then the arrow. | 83 // Then the arrow. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 242 } |
| 244 | 243 |
| 245 void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { | 244 void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { |
| 246 if (background()) { | 245 if (background()) { |
| 247 View::OnPaintBackground(canvas); | 246 View::OnPaintBackground(canvas); |
| 248 return; | 247 return; |
| 249 } | 248 } |
| 250 | 249 |
| 251 gfx::Rect bounds(0, 0, width(), height()); | 250 gfx::Rect bounds(0, 0, width(), height()); |
| 252 NativeTheme::ExtraParams extra; | 251 NativeTheme::ExtraParams extra; |
| 253 const MenuConfig& menu_config = content_view_->GetMenuItem()->GetMenuConfig(); | 252 const MenuConfig& menu_config = MenuConfig::instance(); |
| 254 extra.menu_background.corner_radius = menu_config.corner_radius; | 253 extra.menu_background.corner_radius = menu_config.corner_radius; |
| 255 GetNativeTheme()->Paint(canvas->sk_canvas(), | 254 GetNativeTheme()->Paint(canvas->sk_canvas(), |
| 256 NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra); | 255 NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra); |
| 257 } | 256 } |
| 258 | 257 |
| 259 void MenuScrollViewContainer::GetAccessibleState( | 258 void MenuScrollViewContainer::GetAccessibleState( |
| 260 ui::AXViewState* state) { | 259 ui::AXViewState* state) { |
| 261 // Get the name from the submenu view. | 260 // Get the name from the submenu view. |
| 262 content_view_->GetAccessibleState(state); | 261 content_view_->GetAccessibleState(state); |
| 263 | 262 |
| 264 // Now change the role. | 263 // Now change the role. |
| 265 state->role = ui::AX_ROLE_MENU_BAR; | 264 state->role = ui::AX_ROLE_MENU_BAR; |
| 266 // Some AT (like NVDA) will not process focus events on menu item children | 265 // Some AT (like NVDA) will not process focus events on menu item children |
| 267 // unless a parent claims to be focused. | 266 // unless a parent claims to be focused. |
| 268 state->AddStateFlag(ui::AX_STATE_FOCUSED); | 267 state->AddStateFlag(ui::AX_STATE_FOCUSED); |
| 269 } | 268 } |
| 270 | 269 |
| 271 void MenuScrollViewContainer::OnBoundsChanged( | 270 void MenuScrollViewContainer::OnBoundsChanged( |
| 272 const gfx::Rect& previous_bounds) { | 271 const gfx::Rect& previous_bounds) { |
| 273 gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); | 272 gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); |
| 274 scroll_up_button_->SetVisible(content_pref.height() > height()); | 273 scroll_up_button_->SetVisible(content_pref.height() > height()); |
| 275 scroll_down_button_->SetVisible(content_pref.height() > height()); | 274 scroll_down_button_->SetVisible(content_pref.height() > height()); |
| 276 Layout(); | 275 Layout(); |
| 277 } | 276 } |
| 278 | 277 |
| 279 void MenuScrollViewContainer::CreateDefaultBorder() { | 278 void MenuScrollViewContainer::CreateDefaultBorder() { |
| 280 DCHECK_EQ(arrow_, BubbleBorder::NONE); | 279 DCHECK_EQ(arrow_, BubbleBorder::NONE); |
| 281 bubble_border_ = nullptr; | 280 bubble_border_ = nullptr; |
| 282 | 281 |
| 283 const MenuConfig& menu_config = | 282 const MenuConfig& menu_config = MenuConfig::instance(); |
| 284 content_view_->GetMenuItem()->GetMenuConfig(); | |
| 285 | 283 |
| 286 int padding = menu_config.use_outer_border && menu_config.corner_radius > 0 | 284 int padding = menu_config.use_outer_border && menu_config.corner_radius > 0 |
| 287 ? kBorderPaddingDueToRoundedCorners | 285 ? kBorderPaddingDueToRoundedCorners |
| 288 : 0; | 286 : 0; |
| 289 | 287 |
| 290 int top = menu_config.menu_vertical_border_size + padding; | 288 int top = menu_config.menu_vertical_border_size + padding; |
| 291 int left = menu_config.menu_horizontal_border_size + padding; | 289 int left = menu_config.menu_horizontal_border_size + padding; |
| 292 int bottom = menu_config.menu_vertical_border_size + padding; | 290 int bottom = menu_config.menu_vertical_border_size + padding; |
| 293 int right = menu_config.menu_horizontal_border_size + padding; | 291 int right = menu_config.menu_horizontal_border_size + padding; |
| 294 | 292 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 323 case MENU_ANCHOR_BUBBLE_ABOVE: | 321 case MENU_ANCHOR_BUBBLE_ABOVE: |
| 324 return BubbleBorder::BOTTOM_CENTER; | 322 return BubbleBorder::BOTTOM_CENTER; |
| 325 case MENU_ANCHOR_BUBBLE_BELOW: | 323 case MENU_ANCHOR_BUBBLE_BELOW: |
| 326 return BubbleBorder::TOP_CENTER; | 324 return BubbleBorder::TOP_CENTER; |
| 327 default: | 325 default: |
| 328 return BubbleBorder::NONE; | 326 return BubbleBorder::NONE; |
| 329 } | 327 } |
| 330 } | 328 } |
| 331 | 329 |
| 332 } // namespace views | 330 } // namespace views |
| OLD | NEW |