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