Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: ui/views/controls/menu/menu_scroll_view_container.cc

Issue 1812303002: Added Layer based clipping to MenuScrollViewContainer::MenuScrollView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added TODO with reference to bug. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/menu/menu_scroll_view_container.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/macros.h" 7 #include "base/macros.h"
8 #include "third_party/skia/include/core/SkPaint.h" 8 #include "third_party/skia/include/core/SkPaint.h"
9 #include "third_party/skia/include/core/SkPath.h" 9 #include "third_party/skia/include/core/SkPath.h"
10 #include "ui/accessibility/ax_view_state.h" 10 #include "ui/accessibility/ax_view_state.h"
11 #include "ui/compositor/layer.h"
11 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/color_palette.h" 13 #include "ui/gfx/color_palette.h"
13 #include "ui/views/border.h" 14 #include "ui/views/border.h"
14 #include "ui/views/bubble/bubble_border.h" 15 #include "ui/views/bubble/bubble_border.h"
15 #include "ui/views/controls/menu/menu_config.h" 16 #include "ui/views/controls/menu/menu_config.h"
16 #include "ui/views/controls/menu/menu_controller.h" 17 #include "ui/views/controls/menu/menu_controller.h"
17 #include "ui/views/controls/menu/menu_item_view.h" 18 #include "ui/views/controls/menu/menu_item_view.h"
18 #include "ui/views/controls/menu/submenu_view.h" 19 #include "ui/views/controls/menu/submenu_view.h"
19 #include "ui/views/round_rect_painter.h" 20 #include "ui/views/round_rect_painter.h"
20 21
21 using ui::NativeTheme; 22 using ui::NativeTheme;
22 23
23 namespace views { 24 namespace views {
24 25
25 namespace { 26 namespace {
26 27
27 static const int kBorderPaddingDueToRoundedCorners = 1; 28 static const int kBorderPaddingDueToRoundedCorners = 1;
28 29
29 // MenuScrollButton ------------------------------------------------------------ 30 // MenuScrollButton ------------------------------------------------------------
30 31
31 // MenuScrollButton is used for the scroll buttons when not all menu items fit 32 // MenuScrollButton is used for the scroll buttons when not all menu items fit
32 // on screen. MenuScrollButton forwards appropriate events to the 33 // on screen. MenuScrollButton forwards appropriate events to the
33 // MenuController. 34 // MenuController.
34 35
35 class MenuScrollButton : public View { 36 class MenuScrollButton : public View {
36 public: 37 public:
38 static const char kViewClassName[];
39
37 MenuScrollButton(SubmenuView* host, bool is_up) 40 MenuScrollButton(SubmenuView* host, bool is_up)
38 : host_(host), 41 : host_(host),
39 is_up_(is_up), 42 is_up_(is_up),
40 // Make our height the same as that of other MenuItemViews. 43 // Make our height the same as that of other MenuItemViews.
41 pref_height_(MenuItemView::pref_menu_height()) { 44 pref_height_(MenuItemView::pref_menu_height()) {
42 } 45 }
43 46
47 const char* GetClassName() const override { return kViewClassName; }
48
44 gfx::Size GetPreferredSize() const override { 49 gfx::Size GetPreferredSize() const override {
45 return gfx::Size(MenuConfig::instance().scroll_arrow_height * 2 - 1, 50 return gfx::Size(MenuConfig::instance().scroll_arrow_height * 2 - 1,
46 pref_height_); 51 pref_height_);
47 } 52 }
48 53
49 bool CanDrop(const OSExchangeData& data) override { 54 bool CanDrop(const OSExchangeData& data) override {
50 DCHECK(host_->GetMenuItem()->GetMenuController()); 55 DCHECK(host_->GetMenuItem()->GetMenuController());
51 return true; // Always return true so that drop events are targeted to us. 56 return true; // Always return true so that drop events are targeted to us.
52 } 57 }
53 58
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 118
114 // Direction of the button. 119 // Direction of the button.
115 bool is_up_; 120 bool is_up_;
116 121
117 // Preferred height. 122 // Preferred height.
118 int pref_height_; 123 int pref_height_;
119 124
120 DISALLOW_COPY_AND_ASSIGN(MenuScrollButton); 125 DISALLOW_COPY_AND_ASSIGN(MenuScrollButton);
121 }; 126 };
122 127
128 // static
129 const char MenuScrollButton::kViewClassName[] = "MenuScrollButton";
130
123 } // namespace 131 } // namespace
124 132
125 // MenuScrollView -------------------------------------------------------------- 133 // MenuScrollView --------------------------------------------------------------
126 134
127 // MenuScrollView is a viewport for the SubmenuView. It's reason to exist is so 135 // MenuScrollView is a viewport for the SubmenuView. It's reason to exist is so
128 // that ScrollRectToVisible works. 136 // that ScrollRectToVisible works.
129 // 137 //
130 // NOTE: It is possible to use ScrollView directly (after making it deal with 138 // NOTE: It is possible to use ScrollView directly (after making it deal with
131 // null scrollbars), but clicking on a child of ScrollView forces the window to 139 // null scrollbars), but clicking on a child of ScrollView forces the window to
132 // become active, which we don't want. As we really only need a fraction of 140 // become active, which we don't want. As we really only need a fraction of
133 // what ScrollView does, so we use a one off variant. 141 // what ScrollView does, so we use a one off variant.
134 142
135 class MenuScrollViewContainer::MenuScrollView : public View { 143 class MenuScrollViewContainer::MenuScrollView : public View {
136 public: 144 public:
145 static const char kViewClassName[];
146
137 explicit MenuScrollView(View* child) { 147 explicit MenuScrollView(View* child) {
148 SetPaintToLayer(true);
149 layer()->SetMasksToBounds(true);
150 // TODO(bruthig): Paint bounds opaquely. See http://crbug.com/601135.
151 layer()->SetFillsBoundsOpaquely(false);
138 AddChildView(child); 152 AddChildView(child);
139 } 153 }
140 154
155 const char* GetClassName() const override { return kViewClassName; }
156
141 void ScrollRectToVisible(const gfx::Rect& rect) override { 157 void ScrollRectToVisible(const gfx::Rect& rect) override {
142 // NOTE: this assumes we only want to scroll in the y direction. 158 // NOTE: this assumes we only want to scroll in the y direction.
143 159
144 // If the rect is already visible, do not scroll. 160 // If the rect is already visible, do not scroll.
145 if (GetLocalBounds().Contains(rect)) 161 if (GetLocalBounds().Contains(rect))
146 return; 162 return;
147 163
148 // Scroll just enough so that the rect is visible. 164 // Scroll just enough so that the rect is visible.
149 int dy = 0; 165 int dy = 0;
150 if (rect.bottom() > GetLocalBounds().bottom()) 166 if (rect.bottom() > GetLocalBounds().bottom())
(...skipping 11 matching lines...) Expand all
162 178
163 // Returns the contents, which is the SubmenuView. 179 // Returns the contents, which is the SubmenuView.
164 View* GetContents() { 180 View* GetContents() {
165 return child_at(0); 181 return child_at(0);
166 } 182 }
167 183
168 private: 184 private:
169 DISALLOW_COPY_AND_ASSIGN(MenuScrollView); 185 DISALLOW_COPY_AND_ASSIGN(MenuScrollView);
170 }; 186 };
171 187
188 // static
189 const char MenuScrollViewContainer::MenuScrollView::kViewClassName[] =
190 "MenuScrollViewContainer::MenuScrollView";
191
172 // MenuScrollViewContainer ---------------------------------------------------- 192 // MenuScrollViewContainer ----------------------------------------------------
173 193
194 // static
195 const char MenuScrollViewContainer::kViewClassName[] =
196 "MenuScrollViewContainer";
197
174 MenuScrollViewContainer::MenuScrollViewContainer(SubmenuView* content_view) 198 MenuScrollViewContainer::MenuScrollViewContainer(SubmenuView* content_view)
175 : content_view_(content_view), 199 : content_view_(content_view),
176 arrow_(BubbleBorder::NONE), 200 arrow_(BubbleBorder::NONE),
177 bubble_border_(NULL) { 201 bubble_border_(NULL) {
178 scroll_up_button_ = new MenuScrollButton(content_view, true); 202 scroll_up_button_ = new MenuScrollButton(content_view, true);
179 scroll_down_button_ = new MenuScrollButton(content_view, false); 203 scroll_down_button_ = new MenuScrollButton(content_view, false);
180 AddChildView(scroll_up_button_); 204 AddChildView(scroll_up_button_);
181 AddChildView(scroll_down_button_); 205 AddChildView(scroll_down_button_);
182 206
183 scroll_view_ = new MenuScrollView(content_view); 207 scroll_view_ = new MenuScrollView(content_view);
(...skipping 10 matching lines...) Expand all
194 218
195 bool MenuScrollViewContainer::HasBubbleBorder() { 219 bool MenuScrollViewContainer::HasBubbleBorder() {
196 return arrow_ != BubbleBorder::NONE; 220 return arrow_ != BubbleBorder::NONE;
197 } 221 }
198 222
199 void MenuScrollViewContainer::SetBubbleArrowOffset(int offset) { 223 void MenuScrollViewContainer::SetBubbleArrowOffset(int offset) {
200 DCHECK(HasBubbleBorder()); 224 DCHECK(HasBubbleBorder());
201 bubble_border_->set_arrow_offset(offset); 225 bubble_border_->set_arrow_offset(offset);
202 } 226 }
203 227
228 const char* MenuScrollViewContainer::GetClassName() const {
229 return kViewClassName;
230 }
231
204 gfx::Size MenuScrollViewContainer::GetPreferredSize() const { 232 gfx::Size MenuScrollViewContainer::GetPreferredSize() const {
205 gfx::Size prefsize = scroll_view_->GetContents()->GetPreferredSize(); 233 gfx::Size prefsize = scroll_view_->GetContents()->GetPreferredSize();
206 gfx::Insets insets = GetInsets(); 234 gfx::Insets insets = GetInsets();
207 prefsize.Enlarge(insets.width(), insets.height()); 235 prefsize.Enlarge(insets.width(), insets.height());
208 return prefsize; 236 return prefsize;
209 } 237 }
210 238
211 void MenuScrollViewContainer::Layout() { 239 void MenuScrollViewContainer::Layout() {
212 gfx::Insets insets = GetInsets(); 240 gfx::Insets insets = GetInsets();
213 int x = insets.left(); 241 int x = insets.left();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 case MENU_ANCHOR_BUBBLE_ABOVE: 346 case MENU_ANCHOR_BUBBLE_ABOVE:
319 return BubbleBorder::BOTTOM_CENTER; 347 return BubbleBorder::BOTTOM_CENTER;
320 case MENU_ANCHOR_BUBBLE_BELOW: 348 case MENU_ANCHOR_BUBBLE_BELOW:
321 return BubbleBorder::TOP_CENTER; 349 return BubbleBorder::TOP_CENTER;
322 default: 350 default:
323 return BubbleBorder::NONE; 351 return BubbleBorder::NONE;
324 } 352 }
325 } 353 }
326 354
327 } // namespace views 355 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_scroll_view_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698