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

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: Addressed feedback 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 void set_layer(ui::Layer* layer) { layer_ = layer; }
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_;
Jun Mukai 2013/10/05 01:23:50 one more notes: the original layer of the TrayBubb
michaelpg 2013/12/10 02:04:03 Yes. I've removed the layer_ pointer. I believe it
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);
200 } 199 }
201 200
202 TrayBubbleContentMask::~TrayBubbleContentMask() { 201 TrayBubbleContentMask::~TrayBubbleContentMask() {
203 layer_.set_delegate(NULL); 202 if (layer_)
203 layer_->set_delegate(NULL);
204 } 204 }
205 205
206 void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) { 206 void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) {
207 SkPath path; 207 SkPath path;
208 path.addRoundRect(gfx::RectToSkRect(gfx::Rect(layer()->bounds().size())), 208 path.addRoundRect(gfx::RectToSkRect(gfx::Rect(layer_->bounds().size())),
209 corner_radius_, corner_radius_); 209 corner_radius_, corner_radius_);
210 SkPaint paint; 210 SkPaint paint;
211 paint.setAlpha(255); 211 paint.setAlpha(255);
212 paint.setStyle(SkPaint::kFill_Style); 212 paint.setStyle(SkPaint::kFill_Style);
213 canvas->DrawPath(path, paint); 213 canvas->DrawPath(path, paint);
214 } 214 }
215 215
216 void TrayBubbleContentMask::OnDeviceScaleFactorChanged( 216 void TrayBubbleContentMask::OnDeviceScaleFactorChanged(
217 float device_scale_factor) { 217 float device_scale_factor) {
218 // Redrawing will take care of scale factor change. 218 // Redrawing will take care of scale factor change.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // Inform host items (models) that their views are being destroyed. 342 // Inform host items (models) that their views are being destroyed.
343 if (delegate_) 343 if (delegate_)
344 delegate_->BubbleViewDestroyed(); 344 delegate_->BubbleViewDestroyed();
345 } 345 }
346 346
347 void TrayBubbleView::InitializeAndShowBubble() { 347 void TrayBubbleView::InitializeAndShowBubble() {
348 // Must occur after call to BubbleDelegateView::CreateBubble(). 348 // Must occur after call to BubbleDelegateView::CreateBubble().
349 SetAlignment(params_.arrow_alignment); 349 SetAlignment(params_.arrow_alignment);
350 bubble_border_->UpdateArrowOffset(); 350 bubble_border_->UpdateArrowOffset();
351 351
352 if (get_use_acceleration_when_possible()) 352 if (get_use_acceleration_when_possible()) {
353 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); 353 ui::Layer* mask_layer = new ui::Layer(ui::LAYER_TEXTURED);
354
355 // Set up the TrayBubbleContentMask as the mask layer's delegate.
356 bubble_content_mask_->set_layer(mask_layer);
357 mask_layer->set_delegate(bubble_content_mask_.get());
piman 2013/10/04 18:05:33 nit: I would do this in TrayBubbleContentMask::set
michaelpg 2013/12/10 02:04:03 I'm keeping the actual layer outside of TrayBubble
358
359 layer()->parent()->SetMaskLayer(scoped_ptr<ui::Layer>(mask_layer));
360 }
354 361
355 GetWidget()->Show(); 362 GetWidget()->Show();
356 UpdateBubble(); 363 UpdateBubble();
357 } 364 }
358 365
359 void TrayBubbleView::UpdateBubble() { 366 void TrayBubbleView::UpdateBubble() {
360 SizeToContents(); 367 SizeToContents();
361 if (get_use_acceleration_when_possible()) 368 if (get_use_acceleration_when_possible())
362 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); 369 layer()->parent()->layer_mask_layer()->SetBounds(layer()->bounds());
363 GetWidget()->GetRootView()->SchedulePaint(); 370 GetWidget()->GetRootView()->SchedulePaint();
364 } 371 }
365 372
366 void TrayBubbleView::SetMaxHeight(int height) { 373 void TrayBubbleView::SetMaxHeight(int height) {
367 params_.max_height = height; 374 params_.max_height = height;
368 if (GetWidget()) 375 if (GetWidget())
369 SizeToContents(); 376 SizeToContents();
370 } 377 }
371 378
372 void TrayBubbleView::SetWidth(int width) { 379 void TrayBubbleView::SetWidth(int width) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 const ViewHierarchyChangedDetails& details) { 508 const ViewHierarchyChangedDetails& details) {
502 if (get_use_acceleration_when_possible() && details.is_add && 509 if (get_use_acceleration_when_possible() && details.is_add &&
503 details.child == this) { 510 details.child == this) {
504 details.parent->SetPaintToLayer(true); 511 details.parent->SetPaintToLayer(true);
505 details.parent->SetFillsBoundsOpaquely(true); 512 details.parent->SetFillsBoundsOpaquely(true);
506 details.parent->layer()->SetMasksToBounds(true); 513 details.parent->layer()->SetMasksToBounds(true);
507 } 514 }
508 } 515 }
509 516
510 } // namespace views 517 } // 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