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

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

Issue 24469006: Fixing crash Report - Magic Signature: views::View::ConvertPointToScreen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed - git what are you doing today? Created 7 years, 2 months 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
OLDNEW
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/gfx/animation/slide_animation.h" 7 #include "ui/gfx/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"
11 #include "ui/views/bubble/bubble_frame_view.h" 11 #include "ui/views/bubble/bubble_frame_view.h"
12 #include "ui/views/focus/view_storage.h"
12 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
13 #include "ui/views/widget/widget_observer.h" 14 #include "ui/views/widget/widget_observer.h"
14 15
15 #if defined(OS_WIN) 16 #if defined(OS_WIN)
16 #include "ui/base/win/shell.h" 17 #include "ui/base/win/shell.h"
17 #endif 18 #endif
18 19
19 // The duration of the fade animation in milliseconds. 20 // The duration of the fade animation in milliseconds.
20 static const int kHideFadeDurationMS = 200; 21 static const int kHideFadeDurationMS = 200;
21 22
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return border_widget; 122 return border_widget;
122 } 123 }
123 124
124 } // namespace 125 } // namespace
125 126
126 #endif 127 #endif
127 128
128 BubbleDelegateView::BubbleDelegateView() 129 BubbleDelegateView::BubbleDelegateView()
129 : close_on_esc_(true), 130 : close_on_esc_(true),
130 close_on_deactivate_(true), 131 close_on_deactivate_(true),
131 anchor_view_(NULL), 132 has_anchor_view_(false),
132 anchor_widget_(NULL), 133 anchor_widget_(NULL),
133 move_with_anchor_(false), 134 move_with_anchor_(false),
134 arrow_(BubbleBorder::TOP_LEFT), 135 arrow_(BubbleBorder::TOP_LEFT),
135 shadow_(BubbleBorder::SMALL_SHADOW), 136 shadow_(BubbleBorder::SMALL_SHADOW),
136 color_explicitly_set_(false), 137 color_explicitly_set_(false),
137 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), 138 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin),
138 original_opacity_(255), 139 original_opacity_(255),
139 border_widget_(NULL), 140 border_widget_(NULL),
140 use_focusless_(false), 141 use_focusless_(false),
141 accept_events_(true), 142 accept_events_(true),
142 border_accepts_events_(true), 143 border_accepts_events_(true),
143 adjust_if_offscreen_(true), 144 adjust_if_offscreen_(true),
144 parent_window_(NULL) { 145 parent_window_(NULL) {
145 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 146 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
146 UpdateColorsFromTheme(GetNativeTheme()); 147 UpdateColorsFromTheme(GetNativeTheme());
147 } 148 }
148 149
149 BubbleDelegateView::BubbleDelegateView( 150 BubbleDelegateView::BubbleDelegateView(
150 View* anchor_view, 151 View* anchor_view,
151 BubbleBorder::Arrow arrow) 152 BubbleBorder::Arrow arrow)
152 : close_on_esc_(true), 153 : close_on_esc_(true),
153 close_on_deactivate_(true), 154 close_on_deactivate_(true),
154 anchor_view_(anchor_view), 155 has_anchor_view_(false),
155 anchor_widget_(NULL), 156 anchor_widget_(NULL),
156 move_with_anchor_(false), 157 move_with_anchor_(false),
157 arrow_(arrow), 158 arrow_(arrow),
158 shadow_(BubbleBorder::SMALL_SHADOW), 159 shadow_(BubbleBorder::SMALL_SHADOW),
159 color_explicitly_set_(false), 160 color_explicitly_set_(false),
160 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), 161 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin),
161 original_opacity_(255), 162 original_opacity_(255),
162 border_widget_(NULL), 163 border_widget_(NULL),
163 use_focusless_(false), 164 use_focusless_(false),
164 accept_events_(true), 165 accept_events_(true),
165 border_accepts_events_(true), 166 border_accepts_events_(true),
166 adjust_if_offscreen_(true), 167 adjust_if_offscreen_(true),
167 parent_window_(NULL) { 168 parent_window_(NULL) {
169 SetAnchorView(anchor_view);
168 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 170 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
169 UpdateColorsFromTheme(GetNativeTheme()); 171 UpdateColorsFromTheme(GetNativeTheme());
170 } 172 }
171 173
172 BubbleDelegateView::~BubbleDelegateView() { 174 BubbleDelegateView::~BubbleDelegateView() {
173 if (anchor_widget() != NULL) 175 DetachFromAnchor();
174 anchor_widget()->RemoveObserver(this);
175 anchor_widget_ = NULL;
176 anchor_view_ = NULL;
177 } 176 }
178 177
179 // static 178 // static
180 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { 179 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) {
181 bubble_delegate->Init(); 180 bubble_delegate->Init();
182 // Determine the anchor widget from the anchor view at bubble creation time. 181 // Determine the anchor widget from the anchor view at bubble creation time.
183 bubble_delegate->anchor_widget_ = bubble_delegate->anchor_view() ? 182 bubble_delegate->anchor_widget_ = bubble_delegate->GetAnchorView() ?
184 bubble_delegate->anchor_view()->GetWidget() : NULL; 183 bubble_delegate->GetAnchorView()->GetWidget() : NULL;
185 if (bubble_delegate->anchor_widget()) 184 if (bubble_delegate->anchor_widget())
186 bubble_delegate->anchor_widget()->AddObserver(bubble_delegate); 185 bubble_delegate->anchor_widget()->AddObserver(bubble_delegate);
187 186
188 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate); 187 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate);
189 188
190 #if defined(OS_WIN) 189 #if defined(OS_WIN)
191 #if defined(USE_AURA) 190 #if defined(USE_AURA)
192 // If glass is enabled, the bubble is allowed to extend outside the bounds of 191 // If glass is enabled, the bubble is allowed to extend outside the bounds of
193 // the parent frame and let DWM handle compositing. If not, then we don't 192 // the parent frame and let DWM handle compositing. If not, then we don't
194 // want to allow the bubble to extend the frame because it will be clipped. 193 // want to allow the bubble to extend the frame because it will be clipped.
(...skipping 29 matching lines...) Expand all
224 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( 223 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView(
225 Widget* widget) { 224 Widget* widget) {
226 BubbleFrameView* frame = new BubbleFrameView(margins()); 225 BubbleFrameView* frame = new BubbleFrameView(margins());
227 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ? 226 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ?
228 BubbleBorder::horizontal_mirror(arrow()) : arrow(); 227 BubbleBorder::horizontal_mirror(arrow()) : arrow();
229 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color())); 228 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color()));
230 return frame; 229 return frame;
231 } 230 }
232 231
233 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { 232 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) {
234 if (anchor_widget() == widget) { 233 if (anchor_widget() == widget)
235 anchor_widget_->RemoveObserver(this); 234 DetachFromAnchor();
236 anchor_view_ = NULL;
237 anchor_widget_ = NULL;
238 }
239 } 235 }
240 236
241 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, 237 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget,
242 bool visible) { 238 bool visible) {
243 #if defined(OS_WIN) 239 #if defined(OS_WIN)
244 // On Windows we need to handle this before the bubble is visible or hidden. 240 // On Windows we need to handle this before the bubble is visible or hidden.
245 // Please see the comment on the OnWidgetVisibilityChanging function. On 241 // Please see the comment on the OnWidgetVisibilityChanging function. On
246 // other platforms it is fine to handle it after the bubble is shown/hidden. 242 // other platforms it is fine to handle it after the bubble is shown/hidden.
247 HandleVisibilityChanged(widget, visible); 243 HandleVisibilityChanged(widget, visible);
248 #endif 244 #endif
(...skipping 11 matching lines...) Expand all
260 if (close_on_deactivate() && widget == GetWidget() && !active) 256 if (close_on_deactivate() && widget == GetWidget() && !active)
261 GetWidget()->Close(); 257 GetWidget()->Close();
262 } 258 }
263 259
264 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, 260 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget,
265 const gfx::Rect& new_bounds) { 261 const gfx::Rect& new_bounds) {
266 if (move_with_anchor() && anchor_widget() == widget) 262 if (move_with_anchor() && anchor_widget() == widget)
267 SizeToContents(); 263 SizeToContents();
268 } 264 }
269 265
266 View* BubbleDelegateView::GetAnchorView() const {
267 if (!has_anchor_view_)
268 return NULL;
269 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_);
270 }
271
272 void BubbleDelegateView::SetAnchorView(View* anchor_view) {
273 if (!anchor_view) {
274 if (has_anchor_view_) {
275 has_anchor_view_ = false;
276 ViewStorage::GetInstance()->RemoveView(anchor_view_storage_id_);
277 }
278 return;
279 }
280
281 if (!has_anchor_view_) {
282 anchor_view_storage_id_ = ViewStorage::GetInstance()->CreateStorageID();
283 has_anchor_view_ = true;
284 }
285
286 ViewStorage::GetInstance()->StoreView(anchor_view_storage_id_, anchor_view);
287 }
288
270 gfx::Rect BubbleDelegateView::GetAnchorRect() { 289 gfx::Rect BubbleDelegateView::GetAnchorRect() {
271 if (!anchor_view()) 290 if (!GetAnchorView()) {
291 // If the anchor view was going away, we have to return the last known good
msw 2013/09/27 21:21:53 nit: remove this comment and the curly braces.
Mr4D (OOO till 08-26) 2013/09/27 22:52:21 Done.
292 // position.
272 return anchor_rect_; 293 return anchor_rect_;
273 gfx::Rect anchor_bounds = anchor_view()->GetBoundsInScreen(); 294 }
295 gfx::Rect anchor_bounds = GetAnchorView()->GetBoundsInScreen();
msw 2013/09/27 21:21:53 nit: remove |anchor_bounds|, just use |anchor_rect
Mr4D (OOO till 08-26) 2013/09/27 22:52:21 Done.
274 anchor_bounds.Inset(anchor_view_insets_); 296 anchor_bounds.Inset(anchor_view_insets_);
297 // Remember the last found anchor rect.
298 anchor_rect_ = anchor_bounds;
275 return anchor_bounds; 299 return anchor_bounds;
276 } 300 }
277 301
278 void BubbleDelegateView::StartFade(bool fade_in) { 302 void BubbleDelegateView::StartFade(bool fade_in) {
279 #if defined(USE_AURA) 303 #if defined(USE_AURA)
280 // Use AURA's window layer animation instead of fading. This ensures that 304 // Use AURA's window layer animation instead of fading. This ensures that
281 // hosts which rely on the layer animation callbacks to close the window 305 // hosts which rely on the layer animation callbacks to close the window
282 // work correctly. 306 // work correctly.
283 if (fade_in) 307 if (fade_in)
284 GetWidget()->Show(); 308 GetWidget()->Show();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 if (border_widget_) 454 if (border_widget_)
431 border_widget_->ShowInactive(); 455 border_widget_->ShowInactive();
432 if (anchor_widget() && anchor_widget()->GetTopLevelWidget()) 456 if (anchor_widget() && anchor_widget()->GetTopLevelWidget())
433 anchor_widget()->GetTopLevelWidget()->DisableInactiveRendering(); 457 anchor_widget()->GetTopLevelWidget()->DisableInactiveRendering();
434 } else { 458 } else {
435 if (border_widget_) 459 if (border_widget_)
436 border_widget_->Hide(); 460 border_widget_->Hide();
437 } 461 }
438 } 462 }
439 463
464 void BubbleDelegateView::DetachFromAnchor() {
465 if (anchor_widget_)
466 anchor_widget_->RemoveObserver(this);
467 SetAnchorView(NULL);
468 anchor_widget_ = NULL;
469 }
470
440 } // namespace views 471 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698