Chromium Code Reviews| 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/base/accessibility/accessible_view_state.h" | 9 #include "ui/base/accessibility/accessible_view_state.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/native_theme/native_theme.h" | 11 #include "ui/native_theme/native_theme.h" |
| 12 #include "ui/views/border.h" | 12 #include "ui/views/border.h" |
| 13 #include "ui/views/controls/menu/menu_config.h" | 13 #include "ui/views/controls/menu/menu_config.h" |
| 14 #include "ui/views/controls/menu/menu_controller.h" | 14 #include "ui/views/controls/menu/menu_controller.h" |
| 15 #include "ui/views/controls/menu/menu_item_view.h" | 15 #include "ui/views/controls/menu/menu_item_view.h" |
| 16 #include "ui/views/controls/menu/submenu_view.h" | 16 #include "ui/views/controls/menu/submenu_view.h" |
| 17 #include "ui/views/round_rect_painter.h" | 17 #include "ui/views/round_rect_painter.h" |
| 18 | 18 |
| 19 using ui::NativeTheme; | 19 using ui::NativeTheme; |
| 20 | 20 |
| 21 // Height of the scroll arrow. | 21 // Height of the scroll arrow. |
| 22 // This goes up to 4 with large fonts, but this is close enough for now. | 22 // This goes up to 4 with large fonts, but this is close enough for now. |
| 23 static const int scroll_arrow_height = 3; | 23 static const int scroll_arrow_height = 3; |
| 24 | 24 |
| 25 namespace views { | 25 namespace views { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 static const int kBorderPaddingDueToRoundedCorners = 1; | |
| 30 | |
| 29 // MenuScrollButton ------------------------------------------------------------ | 31 // MenuScrollButton ------------------------------------------------------------ |
| 30 | 32 |
| 31 // MenuScrollButton is used for the scroll buttons when not all menu items fit | 33 // MenuScrollButton is used for the scroll buttons when not all menu items fit |
| 32 // on screen. MenuScrollButton forwards appropriate events to the | 34 // on screen. MenuScrollButton forwards appropriate events to the |
| 33 // MenuController. | 35 // MenuController. |
| 34 | 36 |
| 35 class MenuScrollButton : public View { | 37 class MenuScrollButton : public View { |
| 36 public: | 38 public: |
| 37 MenuScrollButton(SubmenuView* host, bool is_up) | 39 MenuScrollButton(SubmenuView* host, bool is_up) |
| 38 : host_(host), | 40 : host_(host), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 scroll_view_ = new MenuScrollView(content_view); | 174 scroll_view_ = new MenuScrollView(content_view); |
| 173 AddChildView(scroll_view_); | 175 AddChildView(scroll_view_); |
| 174 | 176 |
| 175 const MenuConfig& menu_config = | 177 const MenuConfig& menu_config = |
| 176 content_view_->GetMenuItem()->GetMenuConfig(); | 178 content_view_->GetMenuItem()->GetMenuConfig(); |
| 177 | 179 |
| 178 if (NativeTheme::IsNewMenuStyleEnabled()) { | 180 if (NativeTheme::IsNewMenuStyleEnabled()) { |
| 179 set_border(views::Border::CreateBorderPainter( | 181 set_border(views::Border::CreateBorderPainter( |
| 180 new views::RoundRectPainter( | 182 new views::RoundRectPainter( |
| 181 ui::NativeTheme::instance()->GetSystemColor( | 183 ui::NativeTheme::instance()->GetSystemColor( |
| 182 ui::NativeTheme::kColorId_MenuBorderColor)), | 184 ui::NativeTheme::kColorId_MenuBorderColor), |
| 185 menu_config.corner_radius), | |
| 183 gfx::Insets(menu_config.menu_vertical_border_size, | 186 gfx::Insets(menu_config.menu_vertical_border_size, |
| 184 menu_config.menu_horizontal_border_size, | 187 menu_config.menu_horizontal_border_size, |
| 185 menu_config.menu_vertical_border_size, | 188 menu_config.menu_vertical_border_size, |
| 186 menu_config.menu_horizontal_border_size))); | 189 menu_config.menu_horizontal_border_size))); |
| 187 } else { | 190 } else { |
| 188 set_border( | 191 set_border( |
| 189 Border::CreateEmptyBorder(menu_config.menu_vertical_border_size, | 192 Border::CreateEmptyBorder(menu_config.menu_vertical_border_size, |
| 190 menu_config.menu_horizontal_border_size, | 193 menu_config.menu_horizontal_border_size, |
| 191 menu_config.menu_vertical_border_size, | 194 menu_config.menu_vertical_border_size, |
| 192 menu_config.menu_horizontal_border_size)); | 195 menu_config.menu_horizontal_border_size)); |
| 193 } | 196 } |
| 194 } | 197 } |
| 195 | 198 |
| 196 void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { | 199 void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { |
| 197 if (background()) { | 200 if (background()) { |
| 198 View::OnPaintBackground(canvas); | 201 View::OnPaintBackground(canvas); |
| 199 return; | 202 return; |
| 200 } | 203 } |
| 201 | 204 |
| 202 gfx::Rect bounds(0, 0, width(), height()); | 205 gfx::Rect bounds(0, 0, width(), height()); |
| 203 NativeTheme::ExtraParams extra; | 206 NativeTheme::ExtraParams extra; |
| 207 const MenuConfig& menu_config = content_view_->GetMenuItem()->GetMenuConfig(); | |
| 208 extra.menu_background.corner_radius = menu_config.corner_radius; | |
| 204 GetNativeTheme()->Paint(canvas->sk_canvas(), | 209 GetNativeTheme()->Paint(canvas->sk_canvas(), |
| 205 NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra); | 210 NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra); |
| 206 } | 211 } |
| 207 | 212 |
| 208 void MenuScrollViewContainer::Layout() { | 213 void MenuScrollViewContainer::Layout() { |
| 209 gfx::Insets insets = GetInsets(); | 214 gfx::Insets insets = GetInsets(); |
| 210 int x = insets.left(); | 215 int x = insets.left(); |
| 211 int y = insets.top(); | 216 int y = insets.top(); |
| 212 int width = View::width() - insets.width(); | 217 int width = View::width() - insets.width(); |
| 213 int content_height = height() - insets.height(); | 218 int content_height = height() - insets.height(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 244 // Get the name from the submenu view. | 249 // Get the name from the submenu view. |
| 245 content_view_->GetAccessibleState(state); | 250 content_view_->GetAccessibleState(state); |
| 246 | 251 |
| 247 // Now change the role. | 252 // Now change the role. |
| 248 state->role = ui::AccessibilityTypes::ROLE_MENUBAR; | 253 state->role = ui::AccessibilityTypes::ROLE_MENUBAR; |
| 249 // Some AT (like NVDA) will not process focus events on menu item children | 254 // Some AT (like NVDA) will not process focus events on menu item children |
| 250 // unless a parent claims to be focused. | 255 // unless a parent claims to be focused. |
| 251 state->state = ui::AccessibilityTypes::STATE_FOCUSED; | 256 state->state = ui::AccessibilityTypes::STATE_FOCUSED; |
| 252 } | 257 } |
| 253 | 258 |
| 259 gfx::Insets MenuScrollViewContainer::GetInsets() const { | |
| 260 gfx::Insets insets = View::GetInsets(); | |
|
sky
2013/01/25 20:30:24
Shouldn't this come from the border installed arou
varunjain
2013/01/25 22:57:29
Done.
| |
| 261 const MenuConfig& menu_config = content_view_->GetMenuItem()->GetMenuConfig(); | |
| 262 if (menu_config.corner_radius > 0) { | |
| 263 insets += gfx::Insets(kBorderPaddingDueToRoundedCorners, | |
| 264 kBorderPaddingDueToRoundedCorners, | |
| 265 kBorderPaddingDueToRoundedCorners, | |
| 266 kBorderPaddingDueToRoundedCorners); | |
| 267 } | |
| 268 return insets; | |
| 269 } | |
| 270 | |
| 254 void MenuScrollViewContainer::OnBoundsChanged( | 271 void MenuScrollViewContainer::OnBoundsChanged( |
| 255 const gfx::Rect& previous_bounds) { | 272 const gfx::Rect& previous_bounds) { |
| 256 gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); | 273 gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); |
| 257 scroll_up_button_->SetVisible(content_pref.height() > height()); | 274 scroll_up_button_->SetVisible(content_pref.height() > height()); |
| 258 scroll_down_button_->SetVisible(content_pref.height() > height()); | 275 scroll_down_button_->SetVisible(content_pref.height() > height()); |
| 259 Layout(); | 276 Layout(); |
| 260 } | 277 } |
| 261 | 278 |
| 262 } // namespace views | 279 } // namespace views |
| OLD | NEW |