| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 scroll_down_button_ = new MenuScrollButton(content_view, false); | 170 scroll_down_button_ = new MenuScrollButton(content_view, false); |
| 169 AddChildView(scroll_up_button_); | 171 AddChildView(scroll_up_button_); |
| 170 AddChildView(scroll_down_button_); | 172 AddChildView(scroll_down_button_); |
| 171 | 173 |
| 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 |
| 180 int padding = menu_config.corner_radius > 0 ? |
| 181 kBorderPaddingDueToRoundedCorners : 0; |
| 182 int top = menu_config.menu_vertical_border_size + padding; |
| 183 int left = menu_config.menu_horizontal_border_size + padding; |
| 184 int bottom = menu_config.menu_vertical_border_size + padding; |
| 185 int right = menu_config.menu_horizontal_border_size + padding; |
| 186 |
| 178 if (NativeTheme::IsNewMenuStyleEnabled()) { | 187 if (NativeTheme::IsNewMenuStyleEnabled()) { |
| 179 set_border(views::Border::CreateBorderPainter( | 188 set_border(views::Border::CreateBorderPainter( |
| 180 new views::RoundRectPainter(menu_config.native_theme->GetSystemColor( | 189 new views::RoundRectPainter(menu_config.native_theme->GetSystemColor( |
| 181 ui::NativeTheme::kColorId_MenuBorderColor)), | 190 ui::NativeTheme::kColorId_MenuBorderColor), |
| 182 gfx::Insets(menu_config.menu_vertical_border_size, | 191 menu_config.corner_radius), |
| 183 menu_config.menu_horizontal_border_size, | 192 gfx::Insets(top, left, bottom, right))); |
| 184 menu_config.menu_vertical_border_size, | |
| 185 menu_config.menu_horizontal_border_size))); | |
| 186 } else { | 193 } else { |
| 187 set_border( | 194 set_border(Border::CreateEmptyBorder(top, left, bottom, right)); |
| 188 Border::CreateEmptyBorder(menu_config.menu_vertical_border_size, | |
| 189 menu_config.menu_horizontal_border_size, | |
| 190 menu_config.menu_vertical_border_size, | |
| 191 menu_config.menu_horizontal_border_size)); | |
| 192 } | 195 } |
| 193 } | 196 } |
| 194 | 197 |
| 195 void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { | 198 void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) { |
| 196 if (background()) { | 199 if (background()) { |
| 197 View::OnPaintBackground(canvas); | 200 View::OnPaintBackground(canvas); |
| 198 return; | 201 return; |
| 199 } | 202 } |
| 200 | 203 |
| 201 gfx::Rect bounds(0, 0, width(), height()); | 204 gfx::Rect bounds(0, 0, width(), height()); |
| 202 NativeTheme::ExtraParams extra; | 205 NativeTheme::ExtraParams extra; |
| 206 const MenuConfig& menu_config = content_view_->GetMenuItem()->GetMenuConfig(); |
| 207 extra.menu_background.corner_radius = menu_config.corner_radius; |
| 203 GetNativeTheme()->Paint(canvas->sk_canvas(), | 208 GetNativeTheme()->Paint(canvas->sk_canvas(), |
| 204 NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra); | 209 NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra); |
| 205 } | 210 } |
| 206 | 211 |
| 207 void MenuScrollViewContainer::Layout() { | 212 void MenuScrollViewContainer::Layout() { |
| 208 gfx::Insets insets = GetInsets(); | 213 gfx::Insets insets = GetInsets(); |
| 209 int x = insets.left(); | 214 int x = insets.left(); |
| 210 int y = insets.top(); | 215 int y = insets.top(); |
| 211 int width = View::width() - insets.width(); | 216 int width = View::width() - insets.width(); |
| 212 int content_height = height() - insets.height(); | 217 int content_height = height() - insets.height(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 257 |
| 253 void MenuScrollViewContainer::OnBoundsChanged( | 258 void MenuScrollViewContainer::OnBoundsChanged( |
| 254 const gfx::Rect& previous_bounds) { | 259 const gfx::Rect& previous_bounds) { |
| 255 gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); | 260 gfx::Size content_pref = scroll_view_->GetContents()->GetPreferredSize(); |
| 256 scroll_up_button_->SetVisible(content_pref.height() > height()); | 261 scroll_up_button_->SetVisible(content_pref.height() > height()); |
| 257 scroll_down_button_->SetVisible(content_pref.height() > height()); | 262 scroll_down_button_->SetVisible(content_pref.height() > height()); |
| 258 Layout(); | 263 Layout(); |
| 259 } | 264 } |
| 260 | 265 |
| 261 } // namespace views | 266 } // namespace views |
| OLD | NEW |