Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bubble_frame_view.h" | 5 #include "ui/views/bubble/bubble_frame_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/views/bubble/border_contents_view.h" | 9 #include "ui/views/bubble/border_contents_view.h" |
| 10 #include "ui/views/bubble/bubble_border.h" | 10 #include "ui/views/bubble/bubble_border.h" |
| 11 #include "ui/views/layout/fill_layout.h" | 11 #include "ui/views/layout/fill_layout.h" |
| 12 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
| 13 #include "ui/views/window/client_view.h" | 13 #include "ui/views/window/client_view.h" |
| 14 | 14 |
| 15 namespace views { | 15 namespace views { |
| 16 | 16 |
| 17 BubbleFrameView::BubbleFrameView(BubbleBorder::ArrowLocation location, | 17 BubbleFrameView::BubbleFrameView(BubbleBorder::ArrowLocation location, |
| 18 const gfx::Size& client_size, | 18 const gfx::Size& client_size, |
| 19 SkColor color, | 19 SkColor color, |
| 20 bool allow_bubble_offscreen) | 20 bool allow_bubble_offscreen) |
| 21 : border_contents_(new BorderContentsView()), | 21 : border_contents_(new BorderContentsView()), |
| 22 location_(location), | 22 location_(location), |
| 23 allow_bubble_offscreen_(allow_bubble_offscreen) { | 23 allow_bubble_offscreen_(allow_bubble_offscreen) { |
| 24 border_contents_->Init(); | 24 border_contents_->Init(); |
| 25 bubble_border()->set_arrow_location(location_); | 25 bubble_border()->set_arrow_location(location_); |
| 26 bubble_border()->set_background_color(color); | 26 bubble_border()->set_background_color(color); |
| 27 SetLayoutManager(new views::FillLayout()); | 27 SetLayoutManager(new views::FillLayout()); |
| 28 AddChildView(border_contents_); | 28 AddChildView(border_contents_); |
| 29 gfx::Rect bounds(gfx::Point(), client_size); | 29 gfx::Rect windows_bounds = |
| 30 gfx::Rect windows_bounds = GetWindowBoundsForClientBounds(bounds); | 30 GetWindowBoundsForAnchorAndClientSize(gfx::Rect(), client_size); |
| 31 border_contents_->SetBoundsRect( | 31 border_contents_->SetBoundsRect( |
| 32 gfx::Rect(gfx::Point(), windows_bounds.size())); | 32 gfx::Rect(gfx::Point(), windows_bounds.size())); |
| 33 SetBoundsRect(windows_bounds); | 33 SetBoundsRect(windows_bounds); |
| 34 } | 34 } |
| 35 | 35 |
| 36 BubbleFrameView::~BubbleFrameView() {} | 36 BubbleFrameView::~BubbleFrameView() {} |
| 37 | 37 |
| 38 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { | 38 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { |
| 39 gfx::Insets margin; | 39 gfx::Insets margin; |
| 40 bubble_border()->GetInsets(&margin); | 40 bubble_border()->GetInsets(&margin); |
| 41 margin += border_contents_->content_margins(); | 41 margin += border_contents_->content_margins(); |
| 42 return gfx::Rect(margin.left(), | 42 return gfx::Rect(margin.left(), |
| 43 margin.top(), | 43 margin.top(), |
| 44 std::max(width() - margin.width(), 0), | 44 std::max(width() - margin.width(), 0), |
| 45 std::max(height() - margin.height(), 0)); | 45 std::max(height() - margin.height(), 0)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( | 48 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( |
| 49 const gfx::Rect& client_bounds) const { | 49 const gfx::Rect& client_bounds) const { |
| 50 // The |client_bounds| origin is the bubble arrow anchor point. | 50 // The |client_bounds| origin is the bubble arrow anchor point. |
| 51 gfx::Rect position_relative_to(client_bounds.origin(), gfx::Size()); | 51 gfx::Rect anchor(client_bounds.origin(), gfx::Size()); |
| 52 // The |client_bounds| size is the bubble client view size. | 52 // The |client_bounds| size is the bubble client view size. |
| 53 return GetWindowBoundsForAnchorAndClientSize(anchor, client_bounds.size()); | |
| 54 } | |
| 55 | |
| 56 gfx::Rect BubbleFrameView::GetWindowBoundsForAnchorAndClientSize( | |
| 57 const gfx::Rect& anchor, const gfx::Size& client_size) const { | |
|
msw
2011/12/08 00:40:14
Put params on independent lines.
sail
2011/12/08 01:41:10
Done.
| |
| 53 gfx::Rect content_bounds; | 58 gfx::Rect content_bounds; |
| 54 gfx::Rect window_bounds; | 59 gfx::Rect window_bounds; |
| 55 border_contents_->SizeAndGetBounds(position_relative_to, | 60 border_contents_->SizeAndGetBounds(anchor, |
| 56 location_, | 61 location_, |
| 57 allow_bubble_offscreen_, | 62 allow_bubble_offscreen_, |
| 58 client_bounds.size(), | 63 client_size, |
| 59 &content_bounds, | 64 &content_bounds, |
| 60 &window_bounds); | 65 &window_bounds); |
| 61 return window_bounds; | 66 return window_bounds; |
| 62 } | 67 } |
| 63 | 68 |
| 64 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { | 69 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { |
| 65 return GetWidget()->client_view()->NonClientHitTest(point); | 70 return GetWidget()->client_view()->NonClientHitTest(point); |
| 66 } | 71 } |
| 67 | 72 |
| 68 gfx::Size BubbleFrameView::GetPreferredSize() { | 73 gfx::Size BubbleFrameView::GetPreferredSize() { |
| 69 Widget* widget = GetWidget(); | 74 Widget* widget = GetWidget(); |
| 70 gfx::Rect rect(gfx::Point(), widget->client_view()->GetPreferredSize()); | 75 gfx::Rect rect(gfx::Point(), widget->client_view()->GetPreferredSize()); |
| 71 return widget->non_client_view()->GetWindowBoundsForClientBounds(rect).size(); | 76 return widget->non_client_view()->GetWindowBoundsForClientBounds(rect).size(); |
| 72 } | 77 } |
| 73 | 78 |
| 74 BubbleBorder* BubbleFrameView::bubble_border() const { | 79 BubbleBorder* BubbleFrameView::bubble_border() const { |
| 75 return static_cast<BubbleBorder*>(border_contents_->border()); | 80 return static_cast<BubbleBorder*>(border_contents_->border()); |
| 76 } | 81 } |
| 77 | 82 |
| 78 } // namespace views | 83 } // namespace views |
| OLD | NEW |