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

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: A self check encountered a few things.. 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),
133 last_known_anchor_view_rect_(gfx::Rect()),
msw 2013/09/27 18:20:31 Remove this and others, the default gfx::Rect ctor
Mr4D (OOO till 08-26) 2013/09/27 20:29:35 Done.
132 anchor_widget_(NULL), 134 anchor_widget_(NULL),
135 anchor_rect_(gfx::Rect()),
133 move_with_anchor_(false), 136 move_with_anchor_(false),
134 arrow_(BubbleBorder::TOP_LEFT), 137 arrow_(BubbleBorder::TOP_LEFT),
135 shadow_(BubbleBorder::SMALL_SHADOW), 138 shadow_(BubbleBorder::SMALL_SHADOW),
136 color_explicitly_set_(false), 139 color_explicitly_set_(false),
137 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), 140 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin),
138 original_opacity_(255), 141 original_opacity_(255),
139 border_widget_(NULL), 142 border_widget_(NULL),
140 use_focusless_(false), 143 use_focusless_(false),
141 accept_events_(true), 144 accept_events_(true),
142 border_accepts_events_(true), 145 border_accepts_events_(true),
143 adjust_if_offscreen_(true), 146 adjust_if_offscreen_(true),
144 parent_window_(NULL) { 147 parent_window_(NULL) {
145 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 148 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
146 UpdateColorsFromTheme(GetNativeTheme()); 149 UpdateColorsFromTheme(GetNativeTheme());
147 } 150 }
148 151
149 BubbleDelegateView::BubbleDelegateView( 152 BubbleDelegateView::BubbleDelegateView(
150 View* anchor_view, 153 View* anchor_view,
151 BubbleBorder::Arrow arrow) 154 BubbleBorder::Arrow arrow)
152 : close_on_esc_(true), 155 : close_on_esc_(true),
153 close_on_deactivate_(true), 156 close_on_deactivate_(true),
154 anchor_view_(anchor_view), 157 has_anchor_view_(false),
158 last_known_anchor_view_rect_(gfx::Rect()),
155 anchor_widget_(NULL), 159 anchor_widget_(NULL),
160 anchor_rect_(gfx::Rect()),
156 move_with_anchor_(false), 161 move_with_anchor_(false),
157 arrow_(arrow), 162 arrow_(arrow),
158 shadow_(BubbleBorder::SMALL_SHADOW), 163 shadow_(BubbleBorder::SMALL_SHADOW),
159 color_explicitly_set_(false), 164 color_explicitly_set_(false),
160 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), 165 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin),
161 original_opacity_(255), 166 original_opacity_(255),
162 border_widget_(NULL), 167 border_widget_(NULL),
163 use_focusless_(false), 168 use_focusless_(false),
164 accept_events_(true), 169 accept_events_(true),
165 border_accepts_events_(true), 170 border_accepts_events_(true),
166 adjust_if_offscreen_(true), 171 adjust_if_offscreen_(true),
167 parent_window_(NULL) { 172 parent_window_(NULL) {
173 SetAnchorView(anchor_view);
168 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 174 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
169 UpdateColorsFromTheme(GetNativeTheme()); 175 UpdateColorsFromTheme(GetNativeTheme());
170 } 176 }
171 177
172 BubbleDelegateView::~BubbleDelegateView() { 178 BubbleDelegateView::~BubbleDelegateView() {
173 if (anchor_widget() != NULL) 179 DetachFromAnchor();
174 anchor_widget()->RemoveObserver(this);
175 anchor_widget_ = NULL;
176 anchor_view_ = NULL;
177 } 180 }
178 181
179 // static 182 // static
180 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { 183 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) {
181 bubble_delegate->Init(); 184 bubble_delegate->Init();
182 // Determine the anchor widget from the anchor view at bubble creation time. 185 // Determine the anchor widget from the anchor view at bubble creation time.
183 bubble_delegate->anchor_widget_ = bubble_delegate->anchor_view() ? 186 bubble_delegate->anchor_widget_ = bubble_delegate->AnchorView() ?
184 bubble_delegate->anchor_view()->GetWidget() : NULL; 187 bubble_delegate->AnchorView()->GetWidget() : NULL;
185 if (bubble_delegate->anchor_widget()) 188 if (bubble_delegate->anchor_widget())
186 bubble_delegate->anchor_widget()->AddObserver(bubble_delegate); 189 bubble_delegate->anchor_widget()->AddObserver(bubble_delegate);
187 190
188 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate); 191 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate);
189 192
190 #if defined(OS_WIN) 193 #if defined(OS_WIN)
191 #if defined(USE_AURA) 194 #if defined(USE_AURA)
192 // If glass is enabled, the bubble is allowed to extend outside the bounds of 195 // 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 196 // 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. 197 // want to allow the bubble to extend the frame because it will be clipped.
(...skipping 29 matching lines...) Expand all
224 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( 227 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView(
225 Widget* widget) { 228 Widget* widget) {
226 BubbleFrameView* frame = new BubbleFrameView(margins()); 229 BubbleFrameView* frame = new BubbleFrameView(margins());
227 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ? 230 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ?
228 BubbleBorder::horizontal_mirror(arrow()) : arrow(); 231 BubbleBorder::horizontal_mirror(arrow()) : arrow();
229 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color())); 232 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color()));
230 return frame; 233 return frame;
231 } 234 }
232 235
233 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { 236 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) {
234 if (anchor_widget() == widget) { 237 if (anchor_widget() == widget)
235 anchor_widget_->RemoveObserver(this); 238 DetachFromAnchor();
236 anchor_view_ = NULL;
237 anchor_widget_ = NULL;
238 }
239 } 239 }
240 240
241 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, 241 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget,
242 bool visible) { 242 bool visible) {
243 #if defined(OS_WIN) 243 #if defined(OS_WIN)
244 // On Windows we need to handle this before the bubble is visible or hidden. 244 // On Windows we need to handle this before the bubble is visible or hidden.
245 // Please see the comment on the OnWidgetVisibilityChanging function. On 245 // Please see the comment on the OnWidgetVisibilityChanging function. On
246 // other platforms it is fine to handle it after the bubble is shown/hidden. 246 // other platforms it is fine to handle it after the bubble is shown/hidden.
247 HandleVisibilityChanged(widget, visible); 247 HandleVisibilityChanged(widget, visible);
248 #endif 248 #endif
(...skipping 11 matching lines...) Expand all
260 if (close_on_deactivate() && widget == GetWidget() && !active) 260 if (close_on_deactivate() && widget == GetWidget() && !active)
261 GetWidget()->Close(); 261 GetWidget()->Close();
262 } 262 }
263 263
264 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, 264 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget,
265 const gfx::Rect& new_bounds) { 265 const gfx::Rect& new_bounds) {
266 if (move_with_anchor() && anchor_widget() == widget) 266 if (move_with_anchor() && anchor_widget() == widget)
267 SizeToContents(); 267 SizeToContents();
268 } 268 }
269 269
270 View* BubbleDelegateView::AnchorView() const {
271 if (!has_anchor_view_)
272 return NULL;
273 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_);
274 }
275
276 const gfx::Rect& BubbleDelegateView::AnchorRect() const {
277 return has_anchor_view_ ? last_known_anchor_view_rect_ : anchor_rect_;
278 }
279
280 void BubbleDelegateView::SetAnchorView(View* anchor_view) {
281 if (!anchor_view) {
282 if (has_anchor_view_) {
283 has_anchor_view_ = false;
284 last_known_anchor_view_rect_ = anchor_rect_;
285 ViewStorage::GetInstance()->RemoveView(anchor_view_storage_id_);
286 }
287 return;
288 }
289
290 if (!has_anchor_view_) {
291 anchor_view_storage_id_ = ViewStorage::GetInstance()->CreateStorageID();
msw 2013/09/27 18:20:31 This int needs ctor initialization; either initial
Mr4D (OOO till 08-26) 2013/09/27 20:29:35 According to the header file -1 is not an invalid
msw 2013/09/27 21:21:52 CreateStorageID always uses positive numbers, at l
292 has_anchor_view_ = true;
293 }
294
295 ViewStorage::GetInstance()->StoreView(anchor_view_storage_id_, anchor_view);
296 }
297
298 void BubbleDelegateView::SetAnchorRect(const gfx::Rect& rect) {
msw 2013/09/27 18:20:31 Reverted this to set_anchor_rect with my suggestio
Mr4D (OOO till 08-26) 2013/09/27 20:29:35 Done.
299 anchor_rect_ = rect;
300 last_known_anchor_view_rect_ = rect;
301 }
302
270 gfx::Rect BubbleDelegateView::GetAnchorRect() { 303 gfx::Rect BubbleDelegateView::GetAnchorRect() {
271 if (!anchor_view()) 304 if (!AnchorView()) {
msw 2013/09/27 18:20:31 I think this function can remain largely the same;
Mr4D (OOO till 08-26) 2013/09/27 20:29:35 I did that this way since you *explicitly* told me
msw 2013/09/27 21:21:52 Sorry for not being clear enough yesterday, but th
272 return anchor_rect_; 305 // If the anchor view was going away, we have to return the last known good
273 gfx::Rect anchor_bounds = anchor_view()->GetBoundsInScreen(); 306 // position.
307 return has_anchor_view_ ? last_known_anchor_view_rect_ : anchor_rect_;
308 }
309 gfx::Rect anchor_bounds = AnchorView()->GetBoundsInScreen();
274 anchor_bounds.Inset(anchor_view_insets_); 310 anchor_bounds.Inset(anchor_view_insets_);
311 last_known_anchor_view_rect_ = anchor_bounds;
275 return anchor_bounds; 312 return anchor_bounds;
276 } 313 }
277 314
278 void BubbleDelegateView::StartFade(bool fade_in) { 315 void BubbleDelegateView::StartFade(bool fade_in) {
279 #if defined(USE_AURA) 316 #if defined(USE_AURA)
280 // Use AURA's window layer animation instead of fading. This ensures that 317 // 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 318 // hosts which rely on the layer animation callbacks to close the window
282 // work correctly. 319 // work correctly.
283 if (fade_in) 320 if (fade_in)
284 GetWidget()->Show(); 321 GetWidget()->Show();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 if (border_widget_) 467 if (border_widget_)
431 border_widget_->ShowInactive(); 468 border_widget_->ShowInactive();
432 if (anchor_widget() && anchor_widget()->GetTopLevelWidget()) 469 if (anchor_widget() && anchor_widget()->GetTopLevelWidget())
433 anchor_widget()->GetTopLevelWidget()->DisableInactiveRendering(); 470 anchor_widget()->GetTopLevelWidget()->DisableInactiveRendering();
434 } else { 471 } else {
435 if (border_widget_) 472 if (border_widget_)
436 border_widget_->Hide(); 473 border_widget_->Hide();
437 } 474 }
438 } 475 }
439 476
477 void BubbleDelegateView::DetachFromAnchor() {
478 if (anchor_widget_)
479 anchor_widget_->RemoveObserver(this);
480 SetAnchorView(NULL);
481 anchor_widget_ = NULL;
482 }
483
440 } // namespace views 484 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698