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

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

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