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 "views/bubble/bubble_delegate.h" | 5 #include "views/bubble/bubble_delegate.h" |
6 | 6 |
7 #include "ui/base/animation/slide_animation.h" | 7 #include "ui/base/animation/slide_animation.h" |
8 #include "views/bubble/bubble_frame_view.h" | 8 #include "views/bubble/bubble_frame_view.h" |
9 #include "views/widget/widget.h" | 9 #include "views/widget/widget.h" |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 return border_widget; | 70 return border_widget; |
71 } | 71 } |
72 #endif | 72 #endif |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 BubbleDelegateView::BubbleDelegateView() | 76 BubbleDelegateView::BubbleDelegateView() |
77 : close_on_esc_(true), | 77 : close_on_esc_(true), |
78 close_on_deactivate_(true), | 78 close_on_deactivate_(true), |
79 allow_bubble_offscreen_(false), | 79 allow_bubble_offscreen_(false), |
| 80 anchor_view_(NULL), |
80 arrow_location_(BubbleBorder::TOP_LEFT), | 81 arrow_location_(BubbleBorder::TOP_LEFT), |
81 color_(SK_ColorWHITE), | 82 color_(SK_ColorWHITE), |
82 border_widget_(NULL), | 83 border_widget_(NULL), |
83 use_focusless_(false) { | 84 use_focusless_(false) { |
84 set_background(views::Background::CreateSolidBackground(color_)); | 85 set_background(views::Background::CreateSolidBackground(color_)); |
85 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); | 86 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); |
86 } | 87 } |
87 | 88 |
88 BubbleDelegateView::BubbleDelegateView( | 89 BubbleDelegateView::BubbleDelegateView( |
89 const gfx::Point& anchor_point, | 90 View* anchor_view, |
90 BubbleBorder::ArrowLocation arrow_location, | 91 BubbleBorder::ArrowLocation arrow_location, |
91 const SkColor& color) | 92 const SkColor& color) |
92 : close_on_esc_(true), | 93 : close_on_esc_(true), |
93 close_on_deactivate_(true), | 94 close_on_deactivate_(true), |
94 allow_bubble_offscreen_(false), | 95 allow_bubble_offscreen_(false), |
95 anchor_point_(anchor_point), | 96 anchor_view_(anchor_view), |
96 arrow_location_(arrow_location), | 97 arrow_location_(arrow_location), |
97 color_(color), | 98 color_(color), |
98 original_opacity_(255), | 99 original_opacity_(255), |
99 border_widget_(NULL), | 100 border_widget_(NULL), |
100 use_focusless_(false) { | 101 use_focusless_(false) { |
101 set_background(views::Background::CreateSolidBackground(color_)); | 102 set_background(views::Background::CreateSolidBackground(color_)); |
102 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); | 103 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); |
103 } | 104 } |
104 | 105 |
105 BubbleDelegateView::~BubbleDelegateView() { | 106 BubbleDelegateView::~BubbleDelegateView() { |
106 if (border_widget_) | 107 if (border_widget_) |
107 border_widget_->Close(); | 108 border_widget_->Close(); |
108 } | 109 } |
109 | 110 |
110 // static | 111 // static |
111 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate, | 112 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { |
112 Widget* parent_widget) { | |
113 bubble_delegate->Init(); | 113 bubble_delegate->Init(); |
| 114 Widget* parent_widget = bubble_delegate->anchor_view() ? |
| 115 bubble_delegate->anchor_view()->GetWidget() : NULL; |
114 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget); | 116 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget); |
115 | 117 |
116 #if defined(OS_WIN) && !defined(USE_AURA) | 118 #if defined(OS_WIN) && !defined(USE_AURA) |
| 119 // First set the contents view to initialize view bounds for widget sizing. |
| 120 bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); |
117 bubble_delegate->InitializeBorderWidget(parent_widget); | 121 bubble_delegate->InitializeBorderWidget(parent_widget); |
118 bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); | |
119 bubble_widget->SetBounds(bubble_delegate->GetBubbleClientBounds()); | 122 bubble_widget->SetBounds(bubble_delegate->GetBubbleClientBounds()); |
120 #else | 123 #else |
121 bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); | 124 bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); |
122 #endif | 125 #endif |
123 | 126 |
124 bubble_widget->AddObserver(bubble_delegate); | 127 bubble_widget->AddObserver(bubble_delegate); |
125 if (parent_widget && parent_widget->GetTopLevelWidget()) | 128 if (parent_widget && parent_widget->GetTopLevelWidget()) |
126 parent_widget->GetTopLevelWidget()->DisableInactiveRendering(); | 129 parent_widget->GetTopLevelWidget()->DisableInactiveRendering(); |
127 return bubble_widget; | 130 return bubble_widget; |
128 } | 131 } |
(...skipping 19 matching lines...) Expand all Loading... |
148 | 151 |
149 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, | 152 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, |
150 bool active) { | 153 bool active) { |
151 if (close_on_deactivate() && widget == GetWidget() && !active) { | 154 if (close_on_deactivate() && widget == GetWidget() && !active) { |
152 GetWidget()->RemoveObserver(this); | 155 GetWidget()->RemoveObserver(this); |
153 GetWidget()->Close(); | 156 GetWidget()->Close(); |
154 } | 157 } |
155 } | 158 } |
156 | 159 |
157 gfx::Point BubbleDelegateView::GetAnchorPoint() { | 160 gfx::Point BubbleDelegateView::GetAnchorPoint() { |
158 return anchor_point_; | 161 if (!anchor_view()) |
| 162 return gfx::Point(); |
| 163 |
| 164 BubbleBorder::ArrowLocation location = GetArrowLocation(); |
| 165 gfx::Point anchor(anchor_view()->bounds().CenterPoint()); |
| 166 // By default, pick the middle of |anchor_view_|'s edge opposite the arrow. |
| 167 if (BubbleBorder::is_arrow_on_horizontal(location)) { |
| 168 anchor.SetPoint(anchor_view()->width() / 2, |
| 169 BubbleBorder::is_arrow_on_top(location) ? anchor_view()->height() : 0); |
| 170 } else if (BubbleBorder::has_arrow(location)) { |
| 171 anchor.SetPoint( |
| 172 BubbleBorder::is_arrow_on_left(location) ? anchor_view()->width() : 0, |
| 173 anchor_view_->height() / 2); |
| 174 } |
| 175 View::ConvertPointToScreen(anchor_view(), &anchor); |
| 176 return anchor; |
159 } | 177 } |
160 | 178 |
161 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { | 179 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { |
162 return arrow_location_; | 180 return arrow_location_; |
163 } | 181 } |
164 | 182 |
165 SkColor BubbleDelegateView::GetColor() const { | 183 SkColor BubbleDelegateView::GetColor() const { |
166 return color_; | 184 return color_; |
167 } | 185 } |
168 | 186 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 275 } |
258 | 276 |
259 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 277 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
260 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 278 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
261 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); | 279 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); |
262 return client_bounds; | 280 return client_bounds; |
263 } | 281 } |
264 #endif | 282 #endif |
265 | 283 |
266 } // namespace views | 284 } // namespace views |
OLD | NEW |