Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_bounds(gfx::Rect bounds) { bounds_ = bounds; } |
| 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 gfx::Rect bounds_; |
| 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 : corner_radius_(corner_radius) { |
| 198 corner_radius_(corner_radius) { | |
| 199 layer_.set_delegate(this); | |
| 200 } | 198 } |
| 201 | 199 |
| 202 TrayBubbleContentMask::~TrayBubbleContentMask() { | 200 TrayBubbleContentMask::~TrayBubbleContentMask() { |
| 203 layer_.set_delegate(NULL); | |
| 204 } | 201 } |
| 205 | 202 |
| 206 void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) { | 203 void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) { |
| 207 SkPath path; | 204 SkPath path; |
|
Mr4D (OOO till 08-26)
2013/12/10 15:28:58
Could you please add a comment towards why you are
michaelpg
2013/12/10 22:01:34
As discussed, we are using the layer's bounds. :)
| |
| 208 path.addRoundRect(gfx::RectToSkRect(gfx::Rect(layer()->bounds().size())), | 205 path.addRoundRect(gfx::RectToSkRect(gfx::Rect(bounds_.size())), |
| 209 corner_radius_, corner_radius_); | 206 corner_radius_, corner_radius_); |
| 210 SkPaint paint; | 207 SkPaint paint; |
| 211 paint.setAlpha(255); | 208 paint.setAlpha(255); |
| 212 paint.setStyle(SkPaint::kFill_Style); | 209 paint.setStyle(SkPaint::kFill_Style); |
| 213 canvas->DrawPath(path, paint); | 210 canvas->DrawPath(path, paint); |
| 214 } | 211 } |
| 215 | 212 |
| 216 void TrayBubbleContentMask::OnDeviceScaleFactorChanged( | 213 void TrayBubbleContentMask::OnDeviceScaleFactorChanged( |
| 217 float device_scale_factor) { | 214 float device_scale_factor) { |
| 218 // Redrawing will take care of scale factor change. | 215 // Redrawing will take care of scale factor change. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 SetPaintToLayer(true); | 330 SetPaintToLayer(true); |
| 334 SetFillsBoundsOpaquely(true); | 331 SetFillsBoundsOpaquely(true); |
| 335 | 332 |
| 336 bubble_content_mask_.reset( | 333 bubble_content_mask_.reset( |
| 337 new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius())); | 334 new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius())); |
| 338 } | 335 } |
| 339 } | 336 } |
| 340 | 337 |
| 341 TrayBubbleView::~TrayBubbleView() { | 338 TrayBubbleView::~TrayBubbleView() { |
| 342 mouse_watcher_.reset(); | 339 mouse_watcher_.reset(); |
| 340 | |
| 341 if (get_use_acceleration_when_possible() && | |
|
stevenjb
2013/12/10 22:16:02
Do we need the first check? i.e. if it's false, th
michaelpg
2013/12/10 22:26:08
Yes, you're right. I added the second check becaus
| |
| 342 layer()->parent()->layer_mask_layer()) | |
| 343 layer()->parent()->layer_mask_layer()->set_delegate(NULL); | |
| 344 | |
| 343 // Inform host items (models) that their views are being destroyed. | 345 // Inform host items (models) that their views are being destroyed. |
| 344 if (delegate_) | 346 if (delegate_) |
| 345 delegate_->BubbleViewDestroyed(); | 347 delegate_->BubbleViewDestroyed(); |
| 346 } | 348 } |
| 347 | 349 |
| 348 void TrayBubbleView::InitializeAndShowBubble() { | 350 void TrayBubbleView::InitializeAndShowBubble() { |
| 349 // Must occur after call to BubbleDelegateView::CreateBubble(). | 351 // Must occur after call to BubbleDelegateView::CreateBubble(). |
| 350 SetAlignment(params_.arrow_alignment); | 352 SetAlignment(params_.arrow_alignment); |
| 351 bubble_border_->UpdateArrowOffset(); | 353 bubble_border_->UpdateArrowOffset(); |
| 352 | 354 |
| 353 if (get_use_acceleration_when_possible()) | 355 if (get_use_acceleration_when_possible()) { |
| 354 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); | 356 scoped_ptr<ui::Layer> mask_layer(new ui::Layer(ui::LAYER_TEXTURED)); |
| 357 mask_layer->set_delegate(bubble_content_mask_.get()); | |
| 358 layer()->parent()->SetMaskLayer(mask_layer.Pass()); | |
| 359 } | |
| 355 | 360 |
| 356 GetWidget()->Show(); | 361 GetWidget()->Show(); |
| 357 UpdateBubble(); | 362 UpdateBubble(); |
| 358 } | 363 } |
| 359 | 364 |
| 360 void TrayBubbleView::UpdateBubble() { | 365 void TrayBubbleView::UpdateBubble() { |
| 361 SizeToContents(); | 366 SizeToContents(); |
| 362 if (get_use_acceleration_when_possible()) | 367 if (get_use_acceleration_when_possible()) { |
| 363 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); | 368 bubble_content_mask_->set_bounds(layer()->bounds()); |
| 369 if (layer()->parent()->layer_mask_layer()) | |
| 370 layer()->parent()->layer_mask_layer()->SetBounds(layer()->bounds()); | |
| 371 } | |
| 364 GetWidget()->GetRootView()->SchedulePaint(); | 372 GetWidget()->GetRootView()->SchedulePaint(); |
| 365 } | 373 } |
| 366 | 374 |
| 367 void TrayBubbleView::SetMaxHeight(int height) { | 375 void TrayBubbleView::SetMaxHeight(int height) { |
| 368 params_.max_height = height; | 376 params_.max_height = height; |
| 369 if (GetWidget()) | 377 if (GetWidget()) |
| 370 SizeToContents(); | 378 SizeToContents(); |
| 371 } | 379 } |
| 372 | 380 |
| 373 void TrayBubbleView::SetWidth(int width) { | 381 void TrayBubbleView::SetWidth(int width) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 const ViewHierarchyChangedDetails& details) { | 510 const ViewHierarchyChangedDetails& details) { |
| 503 if (get_use_acceleration_when_possible() && details.is_add && | 511 if (get_use_acceleration_when_possible() && details.is_add && |
| 504 details.child == this) { | 512 details.child == this) { |
| 505 details.parent->SetPaintToLayer(true); | 513 details.parent->SetPaintToLayer(true); |
| 506 details.parent->SetFillsBoundsOpaquely(true); | 514 details.parent->SetFillsBoundsOpaquely(true); |
| 507 details.parent->layer()->SetMasksToBounds(true); | 515 details.parent->layer()->SetMasksToBounds(true); |
| 508 } | 516 } |
| 509 } | 517 } |
| 510 | 518 |
| 511 } // namespace views | 519 } // namespace views |
| OLD | NEW |