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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/bubble/bubble_delegate.cc
diff --git a/ui/views/bubble/bubble_delegate.cc b/ui/views/bubble/bubble_delegate.cc
index af08994d487f5905b3471e806cfb899664de10e0..19867bdf18f1d9dd7acbb349a6c281bad4c61bc7 100644
--- a/ui/views/bubble/bubble_delegate.cc
+++ b/ui/views/bubble/bubble_delegate.cc
@@ -9,6 +9,7 @@
#include "ui/gfx/rect.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/bubble/bubble_frame_view.h"
+#include "ui/views/focus/view_storage.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
@@ -128,7 +129,7 @@ Widget* CreateBorderWidget(BubbleDelegateView* bubble) {
BubbleDelegateView::BubbleDelegateView()
: close_on_esc_(true),
close_on_deactivate_(true),
- anchor_view_(NULL),
+ has_anchor_view_(false),
anchor_widget_(NULL),
move_with_anchor_(false),
arrow_(BubbleBorder::TOP_LEFT),
@@ -151,7 +152,7 @@ BubbleDelegateView::BubbleDelegateView(
BubbleBorder::Arrow arrow)
: close_on_esc_(true),
close_on_deactivate_(true),
- anchor_view_(anchor_view),
+ has_anchor_view_(false),
anchor_widget_(NULL),
move_with_anchor_(false),
arrow_(arrow),
@@ -165,23 +166,21 @@ BubbleDelegateView::BubbleDelegateView(
border_accepts_events_(true),
adjust_if_offscreen_(true),
parent_window_(NULL) {
+ SetAnchorView(anchor_view);
AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
UpdateColorsFromTheme(GetNativeTheme());
}
BubbleDelegateView::~BubbleDelegateView() {
- if (anchor_widget() != NULL)
- anchor_widget()->RemoveObserver(this);
- anchor_widget_ = NULL;
- anchor_view_ = NULL;
+ DetachFromAnchor();
}
// static
Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) {
bubble_delegate->Init();
// Determine the anchor widget from the anchor view at bubble creation time.
- bubble_delegate->anchor_widget_ = bubble_delegate->anchor_view() ?
- bubble_delegate->anchor_view()->GetWidget() : NULL;
+ bubble_delegate->anchor_widget_ = bubble_delegate->GetAnchorView() ?
+ bubble_delegate->GetAnchorView()->GetWidget() : NULL;
if (bubble_delegate->anchor_widget())
bubble_delegate->anchor_widget()->AddObserver(bubble_delegate);
@@ -231,11 +230,8 @@ NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView(
}
void BubbleDelegateView::OnWidgetDestroying(Widget* widget) {
- if (anchor_widget() == widget) {
- anchor_widget_->RemoveObserver(this);
- anchor_view_ = NULL;
- anchor_widget_ = NULL;
- }
+ if (anchor_widget() == widget)
+ DetachFromAnchor();
}
void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget,
@@ -267,11 +263,39 @@ void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget,
SizeToContents();
}
+View* BubbleDelegateView::GetAnchorView() const {
+ if (!has_anchor_view_)
+ return NULL;
+ return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_);
+}
+
+void BubbleDelegateView::SetAnchorView(View* anchor_view) {
+ if (!anchor_view) {
+ if (has_anchor_view_) {
+ has_anchor_view_ = false;
+ ViewStorage::GetInstance()->RemoveView(anchor_view_storage_id_);
+ }
+ return;
+ }
+
+ if (!has_anchor_view_) {
+ anchor_view_storage_id_ = ViewStorage::GetInstance()->CreateStorageID();
+ has_anchor_view_ = true;
+ }
+
+ ViewStorage::GetInstance()->StoreView(anchor_view_storage_id_, anchor_view);
+}
+
gfx::Rect BubbleDelegateView::GetAnchorRect() {
- if (!anchor_view())
+ if (!GetAnchorView()) {
+ // 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.
+ // position.
return anchor_rect_;
- gfx::Rect anchor_bounds = anchor_view()->GetBoundsInScreen();
+ }
+ 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.
anchor_bounds.Inset(anchor_view_insets_);
+ // Remember the last found anchor rect.
+ anchor_rect_ = anchor_bounds;
return anchor_bounds;
}
@@ -437,4 +461,11 @@ void BubbleDelegateView::HandleVisibilityChanged(Widget* widget,
}
}
+void BubbleDelegateView::DetachFromAnchor() {
+ if (anchor_widget_)
+ anchor_widget_->RemoveObserver(this);
+ SetAnchorView(NULL);
+ anchor_widget_ = NULL;
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698