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 30 matching lines...) Expand all Loading... |
41 // to stack bubbles with no arrows correctly. Also calculates the arrow offset. | 41 // to stack bubbles with no arrows correctly. Also calculates the arrow offset. |
42 class TrayBubbleBorder : public views::BubbleBorder { | 42 class TrayBubbleBorder : public views::BubbleBorder { |
43 public: | 43 public: |
44 TrayBubbleBorder(views::View* owner, | 44 TrayBubbleBorder(views::View* owner, |
45 views::View* anchor, | 45 views::View* anchor, |
46 TrayBubbleView::InitParams params) | 46 TrayBubbleView::InitParams params) |
47 : views::BubbleBorder(params.arrow_location, params.shadow), | 47 : views::BubbleBorder(params.arrow_location, params.shadow), |
48 owner_(owner), | 48 owner_(owner), |
49 anchor_(anchor), | 49 anchor_(anchor), |
50 tray_arrow_offset_(params.arrow_offset) { | 50 tray_arrow_offset_(params.arrow_offset) { |
51 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 51 set_alignment(params.arrow_alignment); |
52 set_background_color(params.arrow_color); | 52 set_background_color(params.arrow_color); |
53 set_paint_arrow(!params.hide_arrow); | 53 set_paint_arrow(!params.hide_arrow); |
54 } | 54 } |
55 | 55 |
56 virtual ~TrayBubbleBorder() {} | 56 virtual ~TrayBubbleBorder() {} |
57 | 57 |
58 // Overridden from views::BubbleBorder. | 58 // Overridden from views::BubbleBorder. |
59 // Override views::BubbleBorder to set the bubble on top of the anchor when | 59 // Override views::BubbleBorder to set the bubble on top of the anchor when |
60 // it has no arrow. | 60 // it has no arrow. |
61 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, | 61 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, |
62 const gfx::Size& contents_size) const OVERRIDE { | 62 const gfx::Size& contents_size) const OVERRIDE { |
63 if (arrow_location() != NONE) { | 63 if (has_arrow(arrow_location())) { |
64 return views::BubbleBorder::GetBounds(position_relative_to, | 64 return views::BubbleBorder::GetBounds(position_relative_to, |
65 contents_size); | 65 contents_size); |
66 } | 66 } |
67 | 67 |
68 gfx::Size border_size(contents_size); | 68 gfx::Size border_size(contents_size); |
69 gfx::Insets insets = GetInsets(); | 69 gfx::Insets insets = GetInsets(); |
70 border_size.Enlarge(insets.width(), insets.height()); | 70 border_size.Enlarge(insets.width(), insets.height()); |
71 | 71 |
72 const int x = position_relative_to.x() + | 72 const int x = position_relative_to.x() + |
73 position_relative_to.width() / 2 - border_size.width() / 2; | 73 position_relative_to.width() / 2 - border_size.width() / 2; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 anchor_alignment(anchor_alignment), | 228 anchor_alignment(anchor_alignment), |
229 min_width(min_width), | 229 min_width(min_width), |
230 max_width(max_width), | 230 max_width(max_width), |
231 max_height(0), | 231 max_height(0), |
232 can_activate(false), | 232 can_activate(false), |
233 close_on_deactivate(true), | 233 close_on_deactivate(true), |
234 arrow_color(SK_ColorBLACK), | 234 arrow_color(SK_ColorBLACK), |
235 arrow_location(views::BubbleBorder::NONE), | 235 arrow_location(views::BubbleBorder::NONE), |
236 arrow_offset(kArrowDefaultOffset), | 236 arrow_offset(kArrowDefaultOffset), |
237 hide_arrow(false), | 237 hide_arrow(false), |
238 shadow(views::BubbleBorder::BIG_SHADOW) { | 238 shadow(views::BubbleBorder::BIG_SHADOW), |
| 239 arrow_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE) { |
239 } | 240 } |
240 | 241 |
241 // static | 242 // static |
242 TrayBubbleView* TrayBubbleView::Create(gfx::NativeView parent_window, | 243 TrayBubbleView* TrayBubbleView::Create(gfx::NativeView parent_window, |
243 views::View* anchor, | 244 views::View* anchor, |
244 Delegate* delegate, | 245 Delegate* delegate, |
245 InitParams* init_params) { | 246 InitParams* init_params) { |
246 // Set arrow_location here so that it can be passed correctly to the | 247 // Set arrow_location here so that it can be passed correctly to the |
247 // BubbleView constructor. | 248 // BubbleView constructor. |
248 if (init_params->anchor_type == ANCHOR_TYPE_TRAY) { | 249 if (init_params->anchor_type == ANCHOR_TYPE_TRAY) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 289 } |
289 | 290 |
290 TrayBubbleView::~TrayBubbleView() { | 291 TrayBubbleView::~TrayBubbleView() { |
291 // Inform host items (models) that their views are being destroyed. | 292 // Inform host items (models) that their views are being destroyed. |
292 if (delegate_) | 293 if (delegate_) |
293 delegate_->BubbleViewDestroyed(); | 294 delegate_->BubbleViewDestroyed(); |
294 } | 295 } |
295 | 296 |
296 void TrayBubbleView::InitializeAndShowBubble() { | 297 void TrayBubbleView::InitializeAndShowBubble() { |
297 // Must occur after call to BubbleDelegateView::CreateBubble(). | 298 // Must occur after call to BubbleDelegateView::CreateBubble(). |
298 SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 299 SetAlignment(params_.arrow_alignment); |
299 bubble_border_->UpdateArrowOffset(); | 300 bubble_border_->UpdateArrowOffset(); |
300 | 301 |
301 if (get_use_acceleration_when_possible()) | 302 if (get_use_acceleration_when_possible()) |
302 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); | 303 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); |
303 | 304 |
304 Show(); | 305 Show(); |
305 UpdateBubble(); | 306 UpdateBubble(); |
306 } | 307 } |
307 | 308 |
308 void TrayBubbleView::UpdateBubble() { | 309 void TrayBubbleView::UpdateBubble() { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 views::View* parent, | 410 views::View* parent, |
410 views::View* child) { | 411 views::View* child) { |
411 if (get_use_acceleration_when_possible() && is_add && child == this) { | 412 if (get_use_acceleration_when_possible() && is_add && child == this) { |
412 parent->SetPaintToLayer(true); | 413 parent->SetPaintToLayer(true); |
413 parent->SetFillsBoundsOpaquely(true); | 414 parent->SetFillsBoundsOpaquely(true); |
414 parent->layer()->SetMasksToBounds(true); | 415 parent->layer()->SetMasksToBounds(true); |
415 } | 416 } |
416 } | 417 } |
417 | 418 |
418 } // namespace views | 419 } // namespace views |
OLD | NEW |