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/bubble_delegate.h" | 5 #include "ui/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 "ui/gfx/color_utils.h" | 8 #include "ui/gfx/color_utils.h" |
9 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/rect.h" |
10 #include "ui/native_theme/native_theme.h" | 10 #include "ui/native_theme/native_theme.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 BubbleDelegateView::BubbleDelegateView() | 113 BubbleDelegateView::BubbleDelegateView() |
114 : close_on_esc_(true), | 114 : close_on_esc_(true), |
115 close_on_deactivate_(true), | 115 close_on_deactivate_(true), |
116 anchor_view_(NULL), | 116 anchor_view_(NULL), |
117 anchor_widget_(NULL), | 117 anchor_widget_(NULL), |
118 move_with_anchor_(false), | 118 move_with_anchor_(false), |
119 arrow_(BubbleBorder::TOP_LEFT), | 119 arrow_(BubbleBorder::TOP_LEFT), |
120 shadow_(BubbleBorder::SMALL_SHADOW), | 120 shadow_(BubbleBorder::SMALL_SHADOW), |
121 color_explicitly_set_(false), | 121 color_explicitly_set_(false), |
122 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 122 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
123 match_title_margins_(false), | |
123 original_opacity_(255), | 124 original_opacity_(255), |
124 border_widget_(NULL), | 125 border_widget_(NULL), |
125 use_focusless_(false), | 126 use_focusless_(false), |
126 accept_events_(true), | 127 accept_events_(true), |
127 border_accepts_events_(true), | 128 border_accepts_events_(true), |
128 adjust_if_offscreen_(true), | 129 adjust_if_offscreen_(true), |
129 parent_window_(NULL) { | 130 parent_window_(NULL) { |
130 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 131 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
131 UpdateColorsFromTheme(GetNativeTheme()); | 132 UpdateColorsFromTheme(GetNativeTheme()); |
132 } | 133 } |
133 | 134 |
134 BubbleDelegateView::BubbleDelegateView( | 135 BubbleDelegateView::BubbleDelegateView( |
135 View* anchor_view, | 136 View* anchor_view, |
136 BubbleBorder::Arrow arrow) | 137 BubbleBorder::Arrow arrow) |
137 : close_on_esc_(true), | 138 : close_on_esc_(true), |
138 close_on_deactivate_(true), | 139 close_on_deactivate_(true), |
139 anchor_view_(anchor_view), | 140 anchor_view_(anchor_view), |
140 anchor_widget_(NULL), | 141 anchor_widget_(NULL), |
141 move_with_anchor_(false), | 142 move_with_anchor_(false), |
142 arrow_(arrow), | 143 arrow_(arrow), |
143 shadow_(BubbleBorder::SMALL_SHADOW), | 144 shadow_(BubbleBorder::SMALL_SHADOW), |
144 color_explicitly_set_(false), | 145 color_explicitly_set_(false), |
145 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 146 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
147 match_title_margins_(false), | |
146 original_opacity_(255), | 148 original_opacity_(255), |
147 border_widget_(NULL), | 149 border_widget_(NULL), |
148 use_focusless_(false), | 150 use_focusless_(false), |
149 accept_events_(true), | 151 accept_events_(true), |
150 border_accepts_events_(true), | 152 border_accepts_events_(true), |
151 adjust_if_offscreen_(true), | 153 adjust_if_offscreen_(true), |
152 parent_window_(NULL) { | 154 parent_window_(NULL) { |
153 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 155 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
154 UpdateColorsFromTheme(GetNativeTheme()); | 156 UpdateColorsFromTheme(GetNativeTheme()); |
155 } | 157 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 bool BubbleDelegateView::ShouldShowCloseButton() const { | 203 bool BubbleDelegateView::ShouldShowCloseButton() const { |
202 return false; | 204 return false; |
203 } | 205 } |
204 | 206 |
205 View* BubbleDelegateView::GetContentsView() { | 207 View* BubbleDelegateView::GetContentsView() { |
206 return this; | 208 return this; |
207 } | 209 } |
208 | 210 |
209 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( | 211 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( |
210 Widget* widget) { | 212 Widget* widget) { |
211 BubbleFrameView* frame = new BubbleFrameView(margins()); | 213 BubbleFrameView* frame = new BubbleFrameView(match_title_margins_ ? |
msw
2013/08/08 18:34:26
Could individual bubbles instead call BubbleDelega
Dan Beam
2013/08/08 21:15:59
Done.
| |
214 views::BubbleFrameView::ContentsInsetsToMatchTitle() : margins()); | |
212 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ? | 215 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ? |
213 BubbleBorder::horizontal_mirror(arrow()) : arrow(); | 216 BubbleBorder::horizontal_mirror(arrow()) : arrow(); |
214 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color())); | 217 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color())); |
215 return frame; | 218 return frame; |
216 } | 219 } |
217 | 220 |
221 gfx::Size BubbleDelegateView::GetPreferredSize() { | |
222 if (!match_title_margins_) | |
223 return WidgetDelegateView::GetPreferredSize(); | |
224 | |
225 NonClientFrameView* fv = GetWidget()->non_client_view()->frame_view(); | |
226 int width = fv->GetBoundsForClientView().width() + GetInsets().width(); | |
227 return gfx::Size(width, GetHeightForWidth(width)); | |
228 } | |
229 | |
218 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { | 230 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { |
219 if (anchor_widget() == widget) { | 231 if (anchor_widget() == widget) { |
220 anchor_widget_->RemoveObserver(this); | 232 anchor_widget_->RemoveObserver(this); |
221 anchor_view_ = NULL; | 233 anchor_view_ = NULL; |
222 anchor_widget_ = NULL; | 234 anchor_widget_ = NULL; |
223 } | 235 } |
224 } | 236 } |
225 | 237 |
226 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, | 238 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, |
227 bool visible) { | 239 bool visible) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 #if defined(OS_WIN) && !defined(USE_AURA) | 411 #if defined(OS_WIN) && !defined(USE_AURA) |
400 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 412 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
401 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 413 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
402 client_bounds.Offset( | 414 client_bounds.Offset( |
403 border_widget_->GetWindowBoundsInScreen().OffsetFromOrigin()); | 415 border_widget_->GetWindowBoundsInScreen().OffsetFromOrigin()); |
404 return client_bounds; | 416 return client_bounds; |
405 } | 417 } |
406 #endif | 418 #endif |
407 | 419 |
408 } // namespace views | 420 } // namespace views |
OLD | NEW |