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