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

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: . 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 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()),
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 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()),
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 SetAnchorView(NULL);
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 // Get the latest anchor widget from the anchor view at bubble creation time.
183 bubble_delegate->anchor_widget_ = bubble_delegate->anchor_view() ? 182 bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView());
184 bubble_delegate->anchor_view()->GetWidget() : NULL;
185 if (bubble_delegate->anchor_widget())
186 bubble_delegate->anchor_widget()->AddObserver(bubble_delegate);
187
188 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate); 183 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate);
189 184
190 #if defined(OS_WIN) 185 #if defined(OS_WIN)
191 #if defined(USE_AURA) 186 #if defined(USE_AURA)
192 // If glass is enabled, the bubble is allowed to extend outside the bounds of 187 // 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 188 // 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. 189 // want to allow the bubble to extend the frame because it will be clipped.
195 bubble_delegate->set_adjust_if_offscreen(ui::win::IsAeroGlassEnabled()); 190 bubble_delegate->set_adjust_if_offscreen(ui::win::IsAeroGlassEnabled());
196 #else 191 #else
197 // First set the contents view to initialize view bounds for widget sizing. 192 // First set the contents view to initialize view bounds for widget sizing.
(...skipping 26 matching lines...) Expand all
224 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( 219 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView(
225 Widget* widget) { 220 Widget* widget) {
226 BubbleFrameView* frame = new BubbleFrameView(margins()); 221 BubbleFrameView* frame = new BubbleFrameView(margins());
227 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ? 222 const BubbleBorder::Arrow adjusted_arrow = base::i18n::IsRTL() ?
228 BubbleBorder::horizontal_mirror(arrow()) : arrow(); 223 BubbleBorder::horizontal_mirror(arrow()) : arrow();
229 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color())); 224 frame->SetBubbleBorder(new BubbleBorder(adjusted_arrow, shadow(), color()));
230 return frame; 225 return frame;
231 } 226 }
232 227
233 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { 228 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) {
234 if (anchor_widget() == widget) { 229 if (anchor_widget() == widget)
235 anchor_widget_->RemoveObserver(this); 230 SetAnchorView(NULL);
236 anchor_view_ = NULL;
237 anchor_widget_ = NULL;
238 }
239 } 231 }
240 232
241 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, 233 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget,
242 bool visible) { 234 bool visible) {
243 #if defined(OS_WIN) 235 #if defined(OS_WIN)
244 // On Windows we need to handle this before the bubble is visible or hidden. 236 // On Windows we need to handle this before the bubble is visible or hidden.
245 // Please see the comment on the OnWidgetVisibilityChanging function. On 237 // Please see the comment on the OnWidgetVisibilityChanging function. On
246 // other platforms it is fine to handle it after the bubble is shown/hidden. 238 // other platforms it is fine to handle it after the bubble is shown/hidden.
247 HandleVisibilityChanged(widget, visible); 239 HandleVisibilityChanged(widget, visible);
248 #endif 240 #endif
(...skipping 11 matching lines...) Expand all
260 if (close_on_deactivate() && widget == GetWidget() && !active) 252 if (close_on_deactivate() && widget == GetWidget() && !active)
261 GetWidget()->Close(); 253 GetWidget()->Close();
262 } 254 }
263 255
264 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, 256 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget,
265 const gfx::Rect& new_bounds) { 257 const gfx::Rect& new_bounds) {
266 if (move_with_anchor() && anchor_widget() == widget) 258 if (move_with_anchor() && anchor_widget() == widget)
267 SizeToContents(); 259 SizeToContents();
268 } 260 }
269 261
262 View* BubbleDelegateView::GetAnchorView() const {
sky 2013/09/30 14:58:45 Make order match header.
Mr4D (OOO till 08-26) 2013/09/30 16:22:32 Done.
263 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_);
264 }
265
266 void BubbleDelegateView::SetAnchorView(View* anchor_view) {
267 // When the anchor view gets set the associated anchor widget might
268 // change as well.
269 if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) {
270 if (anchor_widget()) {
271 anchor_widget_->RemoveObserver(this);
272 anchor_widget_ = NULL;
273 }
274 if (anchor_view) {
275 anchor_widget_ = anchor_view->GetWidget();
276 if (anchor_widget_)
277 anchor_widget_->AddObserver(this);
278 }
279 }
280
281 // Remove the old storage item and set the new (if there is one).
282 ViewStorage* view_storage = ViewStorage::GetInstance();
283 if (view_storage->RetrieveView(anchor_view_storage_id_))
284 view_storage->RemoveView(anchor_view_storage_id_);
285
286 if (anchor_view)
287 view_storage->StoreView(anchor_view_storage_id_, anchor_view);
288 }
289
270 gfx::Rect BubbleDelegateView::GetAnchorRect() { 290 gfx::Rect BubbleDelegateView::GetAnchorRect() {
271 if (!anchor_view()) 291 if (!GetAnchorView())
272 return anchor_rect_; 292 return anchor_rect_;
273 gfx::Rect anchor_bounds = anchor_view()->GetBoundsInScreen(); 293
274 anchor_bounds.Inset(anchor_view_insets_); 294 anchor_rect_ = GetAnchorView()->GetBoundsInScreen();
275 return anchor_bounds; 295 anchor_rect_.Inset(anchor_view_insets_);
296 return anchor_rect_;
276 } 297 }
277 298
278 void BubbleDelegateView::StartFade(bool fade_in) { 299 void BubbleDelegateView::StartFade(bool fade_in) {
279 #if defined(USE_AURA) 300 #if defined(USE_AURA)
280 // Use AURA's window layer animation instead of fading. This ensures that 301 // 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 302 // hosts which rely on the layer animation callbacks to close the window
282 // work correctly. 303 // work correctly.
283 if (fade_in) 304 if (fade_in)
284 GetWidget()->Show(); 305 GetWidget()->Show();
285 else 306 else
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 border_widget_->ShowInactive(); 452 border_widget_->ShowInactive();
432 if (anchor_widget() && anchor_widget()->GetTopLevelWidget()) 453 if (anchor_widget() && anchor_widget()->GetTopLevelWidget())
433 anchor_widget()->GetTopLevelWidget()->DisableInactiveRendering(); 454 anchor_widget()->GetTopLevelWidget()->DisableInactiveRendering();
434 } else { 455 } else {
435 if (border_widget_) 456 if (border_widget_)
436 border_widget_->Hide(); 457 border_widget_->Hide();
437 } 458 }
438 } 459 }
439 460
440 } // namespace views 461 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698