Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: ui/views/bubble/bubble_frame_view.cc

Issue 8863009: Fix alignment of avatar bubbles in the NTP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/bubble/bubble_frame_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
58 const gfx::Size& client_size) const {
53 gfx::Rect content_bounds; 59 gfx::Rect content_bounds;
54 gfx::Rect window_bounds; 60 gfx::Rect window_bounds;
55 border_contents_->SizeAndGetBounds(position_relative_to, 61 border_contents_->SizeAndGetBounds(anchor,
56 location_, 62 location_,
57 allow_bubble_offscreen_, 63 allow_bubble_offscreen_,
58 client_bounds.size(), 64 client_size,
59 &content_bounds, 65 &content_bounds,
60 &window_bounds); 66 &window_bounds);
61 return window_bounds; 67 return window_bounds;
62 } 68 }
63 69
64 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { 70 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) {
65 return GetWidget()->client_view()->NonClientHitTest(point); 71 return GetWidget()->client_view()->NonClientHitTest(point);
66 } 72 }
67 73
68 gfx::Size BubbleFrameView::GetPreferredSize() { 74 gfx::Size BubbleFrameView::GetPreferredSize() {
69 Widget* widget = GetWidget(); 75 Widget* widget = GetWidget();
70 gfx::Rect rect(gfx::Point(), widget->client_view()->GetPreferredSize()); 76 gfx::Rect rect(gfx::Point(), widget->client_view()->GetPreferredSize());
71 return widget->non_client_view()->GetWindowBoundsForClientBounds(rect).size(); 77 return widget->non_client_view()->GetWindowBoundsForClientBounds(rect).size();
72 } 78 }
73 79
74 BubbleBorder* BubbleFrameView::bubble_border() const { 80 BubbleBorder* BubbleFrameView::bubble_border() const {
75 return static_cast<BubbleBorder*>(border_contents_->border()); 81 return static_cast<BubbleBorder*>(border_contents_->border());
76 } 82 }
77 83
78 } // namespace views 84 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_frame_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698