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

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

Issue 25961002: Retain tray bubble's rounded corners when the bubble animates out (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« ui/compositor/layer.cc ('K') | « ui/compositor/layer.cc ('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 <algorithm> 7 #include <algorithm>
8 8
9 #include "third_party/skia/include/core/SkCanvas.h" 9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkColor.h" 10 #include "third_party/skia/include/core/SkColor.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 // This mask layer clips the bubble's content so that it does not overwrite the 173 // This mask layer clips the bubble's content so that it does not overwrite the
174 // rounded bubble corners. 174 // rounded bubble corners.
175 // TODO(miket): This does not work on Windows. Implement layer masking or 175 // TODO(miket): This does not work on Windows. Implement layer masking or
176 // alternate solutions if the TrayBubbleView is needed there in the future. 176 // alternate solutions if the TrayBubbleView is needed there in the future.
177 class TrayBubbleContentMask : public ui::LayerDelegate { 177 class TrayBubbleContentMask : public ui::LayerDelegate {
178 public: 178 public:
179 explicit TrayBubbleContentMask(int corner_radius); 179 explicit TrayBubbleContentMask(int corner_radius);
180 virtual ~TrayBubbleContentMask(); 180 virtual ~TrayBubbleContentMask();
181 181
182 ui::Layer* layer() { return &layer_; } 182 ui::Layer* GetLayer();
183 183
184 // Overridden from LayerDelegate. 184 // Overridden from LayerDelegate.
185 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; 185 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
186 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; 186 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
187 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE; 187 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE;
188 188
189 private: 189 private:
190 ui::Layer layer_; 190 ui::Layer* layer_;
michaelpg 2013/10/04 01:12:18 Theoretically this pointer can be invalidated by t
Jun Mukai 2013/10/04 01:39:36 I think you don't need to keep the pointer of the
michaelpg 2013/10/04 01:46:03 Can the bounds of the mask layer not change during
Jun Mukai 2013/10/04 01:56:19 unfortunately the tray can change its size. For ex
michaelpg 2013/10/04 05:56:41 Actually I think the pointer is still needed in th
Jun Mukai 2013/10/04 06:55:45 I think it can be moved to TrayBubbleView's destru
191 SkScalar corner_radius_; 191 SkScalar corner_radius_;
192 192
193 DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask); 193 DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask);
194 }; 194 };
195 195
196 TrayBubbleContentMask::TrayBubbleContentMask(int corner_radius) 196 TrayBubbleContentMask::TrayBubbleContentMask(int corner_radius)
197 : layer_(ui::LAYER_TEXTURED), 197 : layer_(NULL),
198 corner_radius_(corner_radius) { 198 corner_radius_(corner_radius) {
199 layer_.set_delegate(this); 199 // Delay construction of mask layer so it can be owned by its parent layer.
200 } 200 }
201 201
202 TrayBubbleContentMask::~TrayBubbleContentMask() { 202 TrayBubbleContentMask::~TrayBubbleContentMask() {
203 layer_.set_delegate(NULL); 203 layer_->set_delegate(NULL);
204 }
205
206 ui::Layer* TrayBubbleContentMask::GetLayer() {
207 if (!layer_) {
208 layer_ = new ui::Layer(ui::LAYER_TEXTURED);
209 layer_->set_delegate(this);
210 }
piman 2013/10/04 03:44:39 This is weird and upside down. If this doesn't kee
michaelpg 2013/10/04 05:56:41 Ok, this makes more sense. I've made these changes
211 return layer_;
204 } 212 }
205 213
206 void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) { 214 void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) {
207 SkPath path; 215 SkPath path;
208 path.addRoundRect(gfx::RectToSkRect(gfx::Rect(layer()->bounds().size())), 216 path.addRoundRect(gfx::RectToSkRect(gfx::Rect(layer_->bounds().size())),
209 corner_radius_, corner_radius_); 217 corner_radius_, corner_radius_);
210 SkPaint paint; 218 SkPaint paint;
211 paint.setAlpha(255); 219 paint.setAlpha(255);
212 paint.setStyle(SkPaint::kFill_Style); 220 paint.setStyle(SkPaint::kFill_Style);
213 canvas->DrawPath(path, paint); 221 canvas->DrawPath(path, paint);
214 } 222 }
215 223
216 void TrayBubbleContentMask::OnDeviceScaleFactorChanged( 224 void TrayBubbleContentMask::OnDeviceScaleFactorChanged(
217 float device_scale_factor) { 225 float device_scale_factor) {
218 // Redrawing will take care of scale factor change. 226 // Redrawing will take care of scale factor change.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 if (delegate_) 351 if (delegate_)
344 delegate_->BubbleViewDestroyed(); 352 delegate_->BubbleViewDestroyed();
345 } 353 }
346 354
347 void TrayBubbleView::InitializeAndShowBubble() { 355 void TrayBubbleView::InitializeAndShowBubble() {
348 // Must occur after call to BubbleDelegateView::CreateBubble(). 356 // Must occur after call to BubbleDelegateView::CreateBubble().
349 SetAlignment(params_.arrow_alignment); 357 SetAlignment(params_.arrow_alignment);
350 bubble_border_->UpdateArrowOffset(); 358 bubble_border_->UpdateArrowOffset();
351 359
352 if (get_use_acceleration_when_possible()) 360 if (get_use_acceleration_when_possible())
353 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); 361 layer()->parent()->SetMaskLayer(bubble_content_mask_->GetLayer());
354 362
355 GetWidget()->Show(); 363 GetWidget()->Show();
356 UpdateBubble(); 364 UpdateBubble();
357 } 365 }
358 366
359 void TrayBubbleView::UpdateBubble() { 367 void TrayBubbleView::UpdateBubble() {
360 SizeToContents(); 368 SizeToContents();
361 if (get_use_acceleration_when_possible()) 369 if (get_use_acceleration_when_possible())
362 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); 370 bubble_content_mask_->GetLayer()->SetBounds(layer()->bounds());
363 GetWidget()->GetRootView()->SchedulePaint(); 371 GetWidget()->GetRootView()->SchedulePaint();
364 } 372 }
365 373
366 void TrayBubbleView::SetMaxHeight(int height) { 374 void TrayBubbleView::SetMaxHeight(int height) {
367 params_.max_height = height; 375 params_.max_height = height;
368 if (GetWidget()) 376 if (GetWidget())
369 SizeToContents(); 377 SizeToContents();
370 } 378 }
371 379
372 void TrayBubbleView::SetWidth(int width) { 380 void TrayBubbleView::SetWidth(int width) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 const ViewHierarchyChangedDetails& details) { 509 const ViewHierarchyChangedDetails& details) {
502 if (get_use_acceleration_when_possible() && details.is_add && 510 if (get_use_acceleration_when_possible() && details.is_add &&
503 details.child == this) { 511 details.child == this) {
504 details.parent->SetPaintToLayer(true); 512 details.parent->SetPaintToLayer(true);
505 details.parent->SetFillsBoundsOpaquely(true); 513 details.parent->SetFillsBoundsOpaquely(true);
506 details.parent->layer()->SetMasksToBounds(true); 514 details.parent->layer()->SetMasksToBounds(true);
507 } 515 }
508 } 516 }
509 517
510 } // namespace views 518 } // namespace views
OLDNEW
« ui/compositor/layer.cc ('K') | « ui/compositor/layer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698