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" |
11 #include "third_party/skia/include/core/SkPaint.h" | 11 #include "third_party/skia/include/core/SkPaint.h" |
12 #include "third_party/skia/include/core/SkPath.h" | 12 #include "third_party/skia/include/core/SkPath.h" |
13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
14 #include "ui/accessibility/ax_view_state.h" | 14 #include "ui/accessibility/ax_view_state.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
17 #include "ui/compositor/layer_delegate.h" | 17 #include "ui/compositor/layer_delegate.h" |
| 18 #include "ui/compositor/paint_context.h" |
18 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
19 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
20 #include "ui/gfx/geometry/insets.h" | 21 #include "ui/gfx/geometry/insets.h" |
21 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
22 #include "ui/gfx/path.h" | 23 #include "ui/gfx/path.h" |
23 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
24 #include "ui/views/bubble/bubble_frame_view.h" | 25 #include "ui/views/bubble/bubble_frame_view.h" |
25 #include "ui/views/bubble/bubble_window_targeter.h" | 26 #include "ui/views/bubble/bubble_window_targeter.h" |
26 #include "ui/views/layout/box_layout.h" | 27 #include "ui/views/layout/box_layout.h" |
27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // TODO(miket): This does not work on Windows. Implement layer masking or | 176 // TODO(miket): This does not work on Windows. Implement layer masking or |
176 // alternate solutions if the TrayBubbleView is needed there in the future. | 177 // alternate solutions if the TrayBubbleView is needed there in the future. |
177 class TrayBubbleContentMask : public ui::LayerDelegate { | 178 class TrayBubbleContentMask : public ui::LayerDelegate { |
178 public: | 179 public: |
179 explicit TrayBubbleContentMask(int corner_radius); | 180 explicit TrayBubbleContentMask(int corner_radius); |
180 ~TrayBubbleContentMask() override; | 181 ~TrayBubbleContentMask() override; |
181 | 182 |
182 ui::Layer* layer() { return &layer_; } | 183 ui::Layer* layer() { return &layer_; } |
183 | 184 |
184 // Overridden from LayerDelegate. | 185 // Overridden from LayerDelegate. |
185 void OnPaintLayer(gfx::Canvas* canvas) override; | 186 void OnPaintLayer(const ui::PaintContext& context) override; |
186 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | 187 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
187 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 188 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
188 base::Closure PrepareForLayerBoundsChange() override; | 189 base::Closure PrepareForLayerBoundsChange() override; |
189 | 190 |
190 private: | 191 private: |
191 ui::Layer layer_; | 192 ui::Layer layer_; |
192 int corner_radius_; | 193 int corner_radius_; |
193 | 194 |
194 DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask); | 195 DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask); |
195 }; | 196 }; |
196 | 197 |
197 TrayBubbleContentMask::TrayBubbleContentMask(int corner_radius) | 198 TrayBubbleContentMask::TrayBubbleContentMask(int corner_radius) |
198 : layer_(ui::LAYER_TEXTURED), | 199 : layer_(ui::LAYER_TEXTURED), |
199 corner_radius_(corner_radius) { | 200 corner_radius_(corner_radius) { |
200 layer_.set_delegate(this); | 201 layer_.set_delegate(this); |
201 } | 202 } |
202 | 203 |
203 TrayBubbleContentMask::~TrayBubbleContentMask() { | 204 TrayBubbleContentMask::~TrayBubbleContentMask() { |
204 layer_.set_delegate(NULL); | 205 layer_.set_delegate(NULL); |
205 } | 206 } |
206 | 207 |
207 void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) { | 208 void TrayBubbleContentMask::OnPaintLayer(const ui::PaintContext& context) { |
208 SkPaint paint; | 209 SkPaint paint; |
209 paint.setAlpha(255); | 210 paint.setAlpha(255); |
210 paint.setStyle(SkPaint::kFill_Style); | 211 paint.setStyle(SkPaint::kFill_Style); |
211 gfx::Rect rect(layer()->bounds().size()); | 212 gfx::Rect rect(layer()->bounds().size()); |
212 canvas->DrawRoundRect(rect, corner_radius_, paint); | 213 context.canvas()->DrawRoundRect(rect, corner_radius_, paint); |
213 } | 214 } |
214 | 215 |
215 void TrayBubbleContentMask::OnDeviceScaleFactorChanged( | 216 void TrayBubbleContentMask::OnDeviceScaleFactorChanged( |
216 float device_scale_factor) { | 217 float device_scale_factor) { |
217 // Redrawing will take care of scale factor change. | 218 // Redrawing will take care of scale factor change. |
218 } | 219 } |
219 | 220 |
220 base::Closure TrayBubbleContentMask::PrepareForLayerBoundsChange() { | 221 base::Closure TrayBubbleContentMask::PrepareForLayerBoundsChange() { |
221 return base::Closure(); | 222 return base::Closure(); |
222 } | 223 } |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 void TrayBubbleView::ViewHierarchyChanged( | 499 void TrayBubbleView::ViewHierarchyChanged( |
499 const ViewHierarchyChangedDetails& details) { | 500 const ViewHierarchyChangedDetails& details) { |
500 if (details.is_add && details.child == this) { | 501 if (details.is_add && details.child == this) { |
501 details.parent->SetPaintToLayer(true); | 502 details.parent->SetPaintToLayer(true); |
502 details.parent->SetFillsBoundsOpaquely(true); | 503 details.parent->SetFillsBoundsOpaquely(true); |
503 details.parent->layer()->SetMasksToBounds(true); | 504 details.parent->layer()->SetMasksToBounds(true); |
504 } | 505 } |
505 } | 506 } |
506 | 507 |
507 } // namespace views | 508 } // namespace views |
OLD | NEW |