| 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; |
| 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 (layer()->parent()->layer_mask_layer()) |
| 342 layer()->parent()->layer_mask_layer()->set_delegate(NULL); |
| 343 |
| 343 // Inform host items (models) that their views are being destroyed. | 344 // Inform host items (models) that their views are being destroyed. |
| 344 if (delegate_) | 345 if (delegate_) |
| 345 delegate_->BubbleViewDestroyed(); | 346 delegate_->BubbleViewDestroyed(); |
| 346 } | 347 } |
| 347 | 348 |
| 348 void TrayBubbleView::InitializeAndShowBubble() { | 349 void TrayBubbleView::InitializeAndShowBubble() { |
| 349 // Must occur after call to BubbleDelegateView::CreateBubble(). | 350 // Must occur after call to BubbleDelegateView::CreateBubble(). |
| 350 SetAlignment(params_.arrow_alignment); | 351 SetAlignment(params_.arrow_alignment); |
| 351 bubble_border_->UpdateArrowOffset(); | 352 bubble_border_->UpdateArrowOffset(); |
| 352 | 353 |
| 353 if (get_use_acceleration_when_possible()) | 354 if (get_use_acceleration_when_possible()) { |
| 354 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); | 355 scoped_ptr<ui::Layer> mask_layer(new ui::Layer(ui::LAYER_TEXTURED)); |
| 356 mask_layer->set_delegate(bubble_content_mask_.get()); |
| 357 layer()->parent()->SetMaskLayer(mask_layer.Pass()); |
| 358 } |
| 355 | 359 |
| 356 GetWidget()->Show(); | 360 GetWidget()->Show(); |
| 357 UpdateBubble(); | 361 UpdateBubble(); |
| 358 } | 362 } |
| 359 | 363 |
| 360 void TrayBubbleView::UpdateBubble() { | 364 void TrayBubbleView::UpdateBubble() { |
| 361 SizeToContents(); | 365 SizeToContents(); |
| 362 if (get_use_acceleration_when_possible()) | 366 if (get_use_acceleration_when_possible()) { |
| 363 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); | 367 bubble_content_mask_->set_bounds(layer()->bounds()); |
| 368 if (layer()->parent()->layer_mask_layer()) |
| 369 layer()->parent()->layer_mask_layer()->SetBounds(layer()->bounds()); |
| 370 } |
| 364 GetWidget()->GetRootView()->SchedulePaint(); | 371 GetWidget()->GetRootView()->SchedulePaint(); |
| 365 } | 372 } |
| 366 | 373 |
| 367 void TrayBubbleView::SetMaxHeight(int height) { | 374 void TrayBubbleView::SetMaxHeight(int height) { |
| 368 params_.max_height = height; | 375 params_.max_height = height; |
| 369 if (GetWidget()) | 376 if (GetWidget()) |
| 370 SizeToContents(); | 377 SizeToContents(); |
| 371 } | 378 } |
| 372 | 379 |
| 373 void TrayBubbleView::SetWidth(int width) { | 380 void TrayBubbleView::SetWidth(int width) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 const ViewHierarchyChangedDetails& details) { | 509 const ViewHierarchyChangedDetails& details) { |
| 503 if (get_use_acceleration_when_possible() && details.is_add && | 510 if (get_use_acceleration_when_possible() && details.is_add && |
| 504 details.child == this) { | 511 details.child == this) { |
| 505 details.parent->SetPaintToLayer(true); | 512 details.parent->SetPaintToLayer(true); |
| 506 details.parent->SetFillsBoundsOpaquely(true); | 513 details.parent->SetFillsBoundsOpaquely(true); |
| 507 details.parent->layer()->SetMasksToBounds(true); | 514 details.parent->layer()->SetMasksToBounds(true); |
| 508 } | 515 } |
| 509 } | 516 } |
| 510 | 517 |
| 511 } // namespace views | 518 } // namespace views |
| OLD | NEW |