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

Side by Side Diff: ui/views/bubble/tray_bubble_view.cc

Issue 11293124: Remove top and bottom margins from TrayBubbleView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed. Restored previous behavior on Windows non-aura. Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/bubble/tray_bubble_view.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/bubble/tray_bubble_view.h" 5 #include "ui/views/bubble/tray_bubble_view.h"
6 6
7 #include "third_party/skia/include/core/SkCanvas.h" 7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkColor.h" 8 #include "third_party/skia/include/core/SkColor.h"
9 #include "third_party/skia/include/core/SkPaint.h" 9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "third_party/skia/include/core/SkPath.h" 10 #include "third_party/skia/include/core/SkPath.h"
11 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 11 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
12 #include "ui/base/accessibility/accessible_view_state.h" 12 #include "ui/base/accessibility/accessible_view_state.h"
13 #include "ui/base/events/event.h" 13 #include "ui/base/events/event.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/insets.h" 16 #include "ui/gfx/insets.h"
17 #include "ui/gfx/path.h" 17 #include "ui/gfx/path.h"
18 #include "ui/gfx/rect.h"
18 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
19 #include "ui/views/bubble/bubble_frame_view.h" 20 #include "ui/views/bubble/bubble_frame_view.h"
20 #include "ui/views/layout/box_layout.h" 21 #include "ui/views/layout/box_layout.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 23
23 namespace { 24 namespace {
24 25
25 // Inset the arrow a bit from the edge. 26 // Inset the arrow a bit from the edge.
26 const int kArrowMinOffset = 20; 27 const int kArrowMinOffset = 20;
27 const int kBubbleSpacing = 20; 28 const int kBubbleSpacing = 20;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 111 }
111 112
112 private: 113 private:
113 views::View* owner_; 114 views::View* owner_;
114 views::View* anchor_; 115 views::View* anchor_;
115 const int tray_arrow_offset_; 116 const int tray_arrow_offset_;
116 117
117 DISALLOW_COPY_AND_ASSIGN(TrayBubbleBorder); 118 DISALLOW_COPY_AND_ASSIGN(TrayBubbleBorder);
118 }; 119 };
119 120
121 #if defined(OS_WIN) && !defined(USE_AURA)
120 // Custom background for TrayBubbleView. Fills in the top and bottom margins 122 // Custom background for TrayBubbleView. Fills in the top and bottom margins
121 // with appropriate background colors without overwriting the rounded corners. 123 // with appropriate background colors without overwriting the rounded corners.
122 class TrayBubbleBackground : public views::Background { 124 class TrayBubbleBackground : public views::Background {
123 public: 125 public:
124 explicit TrayBubbleBackground(views::BubbleBorder* border, 126 explicit TrayBubbleBackground(views::BubbleBorder* border,
125 SkColor top_color, 127 SkColor top_color,
126 SkColor bottom_color) 128 SkColor bottom_color)
127 : border_(border), 129 : border_(border),
128 top_color_(top_color), 130 top_color_(top_color),
129 bottom_color_(bottom_color), 131 bottom_color_(bottom_color),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 166 }
165 167
166 private: 168 private:
167 views::BubbleBorder* border_; 169 views::BubbleBorder* border_;
168 SkColor top_color_; 170 SkColor top_color_;
169 SkColor bottom_color_; 171 SkColor bottom_color_;
170 SkScalar radius_; 172 SkScalar radius_;
171 173
172 DISALLOW_COPY_AND_ASSIGN(TrayBubbleBackground); 174 DISALLOW_COPY_AND_ASSIGN(TrayBubbleBackground);
173 }; 175 };
176 #else
177 class TrayBubbleContentMask : public ui::Layer, public ui::LayerDelegate {
178 public:
179 TrayBubbleContentMask(views::BubbleBorder* border)
180 : Layer(ui::LAYER_TEXTURED),
181 radius_(SkIntToScalar(border->GetBorderCornerRadius() - 1)) {
182 set_delegate(this);
183 }
184
185 // Overridden from LayerDelegate:
186 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
187 SkPath path;
188 path.addRoundRect(gfx::RectToSkRect(gfx::Rect(bounds().size())),
189 radius_, radius_);
190 SkPaint paint;
191 paint.setAlpha(255);
192 paint.setStyle(SkPaint::kFill_Style);
193 canvas->DrawPath(path, paint);
194 }
195
196 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {
197 }
198
199 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE {
200 return base::Closure();
201 }
202
203 private:
204 SkScalar radius_;
205
206 DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask);
207 };
208 #endif // defined(OS_WIN) && !defined(USE_AURA)
174 209
175 // Custom layout for the bubble-view. Does the default box-layout if there is 210 // Custom layout for the bubble-view. Does the default box-layout if there is
176 // enough height. Otherwise, makes sure the bottom rows are visible. 211 // enough height. Otherwise, makes sure the bottom rows are visible.
177 class BottomAlignedBoxLayout : public views::BoxLayout { 212 class BottomAlignedBoxLayout : public views::BoxLayout {
178 public: 213 public:
179 explicit BottomAlignedBoxLayout(TrayBubbleView* bubble_view) 214 explicit BottomAlignedBoxLayout(TrayBubbleView* bubble_view)
180 : views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0), 215 : views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0),
181 bubble_view_(bubble_view) { 216 bubble_view_(bubble_view) {
182 } 217 }
183 218
(...skipping 21 matching lines...) Expand all
205 } 240 }
206 241
207 TrayBubbleView* bubble_view_; 242 TrayBubbleView* bubble_view_;
208 243
209 DISALLOW_COPY_AND_ASSIGN(BottomAlignedBoxLayout); 244 DISALLOW_COPY_AND_ASSIGN(BottomAlignedBoxLayout);
210 }; 245 };
211 246
212 } // namespace internal 247 } // namespace internal
213 248
214 using internal::TrayBubbleBorder; 249 using internal::TrayBubbleBorder;
250 #if defined(OS_WIN) && !defined(USE_AURA)
215 using internal::TrayBubbleBackground; 251 using internal::TrayBubbleBackground;
252 #else
253 using internal::TrayBubbleContentMask;
254 #endif
216 using internal::BottomAlignedBoxLayout; 255 using internal::BottomAlignedBoxLayout;
217 256
218 // static 257 // static
219 const int TrayBubbleView::InitParams::kArrowDefaultOffset = -1; 258 const int TrayBubbleView::InitParams::kArrowDefaultOffset = -1;
220 259
221 TrayBubbleView::InitParams::InitParams(AnchorType anchor_type, 260 TrayBubbleView::InitParams::InitParams(AnchorType anchor_type,
222 AnchorAlignment anchor_alignment, 261 AnchorAlignment anchor_alignment,
223 int bubble_width) 262 int bubble_width)
224 : anchor_type(anchor_type), 263 : anchor_type(anchor_type),
225 anchor_alignment(anchor_alignment), 264 anchor_alignment(anchor_alignment),
226 bubble_width(bubble_width), 265 bubble_width(bubble_width),
227 max_height(0), 266 max_height(0),
228 can_activate(false), 267 can_activate(false),
229 close_on_deactivate(true), 268 close_on_deactivate(true),
269 #if defined(OS_WIN) && !defined(USE_AURA)
230 top_color(SK_ColorBLACK), 270 top_color(SK_ColorBLACK),
271 #endif
231 arrow_color(SK_ColorBLACK), 272 arrow_color(SK_ColorBLACK),
232 arrow_location(views::BubbleBorder::NONE), 273 arrow_location(views::BubbleBorder::NONE),
233 arrow_offset(kArrowDefaultOffset), 274 arrow_offset(kArrowDefaultOffset),
234 shadow(views::BubbleBorder::BIG_SHADOW) { 275 shadow(views::BubbleBorder::BIG_SHADOW) {
235 } 276 }
236 277
237 // static 278 // static
238 TrayBubbleView* TrayBubbleView::Create(gfx::NativeView parent_window, 279 TrayBubbleView* TrayBubbleView::Create(gfx::NativeView parent_window,
239 views::View* anchor, 280 views::View* anchor,
240 Delegate* delegate, 281 Delegate* delegate,
(...skipping 17 matching lines...) Expand all
258 } 299 }
259 300
260 TrayBubbleView::TrayBubbleView(gfx::NativeView parent_window, 301 TrayBubbleView::TrayBubbleView(gfx::NativeView parent_window,
261 views::View* anchor, 302 views::View* anchor,
262 Delegate* delegate, 303 Delegate* delegate,
263 const InitParams& init_params) 304 const InitParams& init_params)
264 : views::BubbleDelegateView(anchor, init_params.arrow_location), 305 : views::BubbleDelegateView(anchor, init_params.arrow_location),
265 params_(init_params), 306 params_(init_params),
266 delegate_(delegate), 307 delegate_(delegate),
267 bubble_border_(NULL), 308 bubble_border_(NULL),
309 #if defined(OS_WIN) && !defined(USE_AURA)
268 bubble_background_(NULL), 310 bubble_background_(NULL),
311 #endif
269 is_gesture_dragging_(false) { 312 is_gesture_dragging_(false) {
270 set_parent_window(parent_window); 313 set_parent_window(parent_window);
271 set_notify_enter_exit_on_child(true); 314 set_notify_enter_exit_on_child(true);
272 set_close_on_deactivate(init_params.close_on_deactivate); 315 set_close_on_deactivate(init_params.close_on_deactivate);
273 SetPaintToLayer(true); 316 SetPaintToLayer(true);
274 SetFillsBoundsOpaquely(true); 317 SetFillsBoundsOpaquely(true);
275 318
276 bubble_border_ = new TrayBubbleBorder(this, anchor_view(), params_); 319 bubble_border_ = new TrayBubbleBorder(this, anchor_view(), params_);
277 320
321 #if defined(OS_WIN) && !defined(USE_AURA)
322 // On Windows non-aura, the bubble's top and bottom margins are painted by a
323 // custom background class that is aware of the bubble's rounded corners.
278 bubble_background_ = new TrayBubbleBackground( 324 bubble_background_ = new TrayBubbleBackground(
279 bubble_border_, init_params.top_color, init_params.arrow_color); 325 bubble_border_, init_params.top_color, init_params.arrow_color);
280
281 // Inset the view on the top and bottom by the corner radius to avoid drawing
282 // over the the bubble corners.
283 const int radius = bubble_background_->radius(); 326 const int radius = bubble_background_->radius();
284 set_margins(gfx::Insets(radius, 0, radius, 0)); 327 set_margins(gfx::Insets(radius, 0, radius, 0));
328 #else
329 // On all other platforms, the bubble's content is allowed to extend to the
330 // bubble's edges and a mask layer ensures that the bubble's rounded corners
331 // do not get overwritten.
332 bubble_content_mask_.reset(new TrayBubbleContentMask(bubble_border_));
sky 2012/11/07 15:30:37 Can we instead use ClipPath when painting so that
bartfab (slow) 2012/11/07 15:34:06 The problem is that the ash tray context menu cont
333 set_margins(gfx::Insets());
334 #endif // defined(OS_WIN) && !defined(USE_AURA)
285 } 335 }
286 336
287 TrayBubbleView::~TrayBubbleView() { 337 TrayBubbleView::~TrayBubbleView() {
288 // Inform host items (models) that their views are being destroyed. 338 // Inform host items (models) that their views are being destroyed.
289 if (delegate_) 339 if (delegate_)
290 delegate_->BubbleViewDestroyed(); 340 delegate_->BubbleViewDestroyed();
291 } 341 }
292 342
293 void TrayBubbleView::InitializeAndShowBubble() { 343 void TrayBubbleView::InitializeAndShowBubble() {
294 // Must occur after call to BubbleDelegateView::CreateBubble(). 344 // Must occur after call to BubbleDelegateView::CreateBubble().
295 SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 345 SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
296 bubble_border_->UpdateArrowOffset(); 346 bubble_border_->UpdateArrowOffset();
297 347
348 #if !defined(OS_WIN) || defined(USE_AURA)
349 layer()->parent()->SetMaskLayer(bubble_content_mask_.get());
350 #endif
351
298 Show(); 352 Show();
299 UpdateBubble(); 353 UpdateBubble();
300 } 354 }
301 355
302 void TrayBubbleView::UpdateBubble() { 356 void TrayBubbleView::UpdateBubble() {
303 SizeToContents(); 357 SizeToContents();
358 #if !defined(OS_WIN) || defined(USE_AURA)
359 bubble_content_mask_->SetBounds(layer()->bounds());
360 #endif
304 GetWidget()->GetRootView()->SchedulePaint(); 361 GetWidget()->GetRootView()->SchedulePaint();
305 } 362 }
306 363
307 void TrayBubbleView::SetMaxHeight(int height) { 364 void TrayBubbleView::SetMaxHeight(int height) {
308 params_.max_height = height; 365 params_.max_height = height;
309 if (GetWidget()) 366 if (GetWidget())
310 SizeToContents(); 367 SizeToContents();
311 } 368 }
312 369
313 void TrayBubbleView::SetPaintArrow(bool paint_arrow) { 370 void TrayBubbleView::SetPaintArrow(bool paint_arrow) {
(...skipping 20 matching lines...) Expand all
334 391
335 bool TrayBubbleView::CanActivate() const { 392 bool TrayBubbleView::CanActivate() const {
336 return params_.can_activate; 393 return params_.can_activate;
337 } 394 }
338 395
339 // Overridden to create BubbleFrameView and set a custom border and background. 396 // Overridden to create BubbleFrameView and set a custom border and background.
340 views::NonClientFrameView* TrayBubbleView::CreateNonClientFrameView( 397 views::NonClientFrameView* TrayBubbleView::CreateNonClientFrameView(
341 views::Widget* widget) { 398 views::Widget* widget) {
342 views::BubbleFrameView* bubble_frame_view = 399 views::BubbleFrameView* bubble_frame_view =
343 new views::BubbleFrameView(margins(), bubble_border_); 400 new views::BubbleFrameView(margins(), bubble_border_);
401 #if defined(OS_WIN) && !defined(USE_AURA)
344 bubble_frame_view->set_background(bubble_background_); 402 bubble_frame_view->set_background(bubble_background_);
403 #endif
345 return bubble_frame_view; 404 return bubble_frame_view;
346 } 405 }
347 406
348 bool TrayBubbleView::WidgetHasHitTestMask() const { 407 bool TrayBubbleView::WidgetHasHitTestMask() const {
349 return true; 408 return true;
350 } 409 }
351 410
352 void TrayBubbleView::GetWidgetHitTestMask(gfx::Path* mask) const { 411 void TrayBubbleView::GetWidgetHitTestMask(gfx::Path* mask) const {
353 DCHECK(mask); 412 DCHECK(mask);
354 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds())); 413 mask->addRect(gfx::RectToSkRect(GetBubbleFrameView()->GetContentsBounds()));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 views::View* parent, 446 views::View* parent,
388 views::View* child) { 447 views::View* child) {
389 if (is_add && child == this) { 448 if (is_add && child == this) {
390 parent->SetPaintToLayer(true); 449 parent->SetPaintToLayer(true);
391 parent->SetFillsBoundsOpaquely(true); 450 parent->SetFillsBoundsOpaquely(true);
392 parent->layer()->SetMasksToBounds(true); 451 parent->layer()->SetMasksToBounds(true);
393 } 452 }
394 } 453 }
395 454
396 } // namespace views 455 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/tray_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698