diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-09 20:55:54 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-09 20:55:54 +0000 |
commit | 5c2b98bd412b23db58345799a625b406b858ad4f (patch) | |
tree | 0e5dc8d2e4368d8d90e8d0367c5350794b610a36 /chrome | |
parent | bc2f935b5525528f5b2c90c8de3a94be7d56b369 (diff) | |
download | chromium_src-5c2b98bd412b23db58345799a625b406b858ad4f.zip chromium_src-5c2b98bd412b23db58345799a625b406b858ad4f.tar.gz chromium_src-5c2b98bd412b23db58345799a625b406b858ad4f.tar.bz2 |
Fixes crash in ResizeCorner. ResizeCorner was caching the BrowserView
that created it, but if a tab contained a download shelf and was
dragged to a new window the ResizeCorner would be referencing the
wrong BrowserView. I've changed the code to look up the ancestor
BrowserView as necessary.
BUG=8477
TEST=see bug
Review URL: http://codereview.chromium.org/41010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11285 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 27 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 2 | ||||
-rw-r--r-- | chrome/views/view.cc | 8 | ||||
-rw-r--r-- | chrome/views/view.h | 4 |
4 files changed, 34 insertions, 7 deletions
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 381de05..ebd48887 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -93,6 +93,9 @@ static const int kWindowBorderWidth = 5; // If not -1, windows are shown with this state. static int explicit_show_state = -1; +// Returned from BrowserView::GetClassName. +static const char kBrowserViewClassName[] = "browser/views/BrowserView"; + static const struct { bool separator; int command; @@ -126,12 +129,11 @@ static const struct { class ResizeCorner : public views::View { public: - explicit ResizeCorner(const BrowserView* parent) - : parent_(parent) { - } + ResizeCorner() { } virtual void Paint(ChromeCanvas* canvas) { - if (parent_ && !parent_->CanCurrentlyResize()) + BrowserView* browser = GetBrowserView(); + if (browser && !browser->CanCurrentlyResize()) return; SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( @@ -158,7 +160,8 @@ class ResizeCorner : public views::View { } virtual gfx::Size GetPreferredSize() { - return (parent_ && !parent_->CanCurrentlyResize()) ? + BrowserView* browser = GetBrowserView(); + return (browser && !browser->CanCurrentlyResize()) ? gfx::Size() : GetSize(); } @@ -174,7 +177,13 @@ class ResizeCorner : public views::View { } private: - const BrowserView* parent_; + // Returns the BrowserView we're displayed in. Returns NULL if we're not + // currently in a browser view. + BrowserView* GetBrowserView() { + View* browser = GetAncestorWithClassName(kBrowserViewClassName); + return browser ? static_cast<BrowserView*>(browser) : NULL; + } + DISALLOW_COPY_AND_ASSIGN(ResizeCorner); }; @@ -1185,6 +1194,10 @@ int BrowserView::NonClientHitTest(const gfx::Point& point) { /////////////////////////////////////////////////////////////////////////////// // BrowserView, views::View overrides: +std::string BrowserView::GetClassName() const { + return kBrowserViewClassName; +} + void BrowserView::Layout() { int top = LayoutTabStrip(); top = LayoutToolbar(top); @@ -1445,7 +1458,7 @@ bool BrowserView::MaybeShowDownloadShelf(TabContents* contents) { if (contents && contents->IsDownloadShelfVisible()) { new_shelf = static_cast<DownloadShelfView*>(contents->GetDownloadShelf()); if (new_shelf != active_download_shelf_) - new_shelf->AddChildView(new ResizeCorner(this)); + new_shelf->AddChildView(new ResizeCorner()); } return UpdateChildViewAndLayout(new_shelf, &active_download_shelf_); } diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 77ff8ae..8b9173c 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -262,6 +262,8 @@ class BrowserView : public BrowserWindow, } #endif + virtual std::string GetClassName() const; + protected: // Overridden from views::View: virtual void Layout(); diff --git a/chrome/views/view.cc b/chrome/views/view.cc index e0fc3573..00c3e4b 100644 --- a/chrome/views/view.cc +++ b/chrome/views/view.cc @@ -1490,6 +1490,14 @@ std::string View::GetClassName() const { return kViewClassName; } +View* View::GetAncestorWithClassName(const std::string& name) { + for (View* view = this; view; view = view->GetParent()) { + if (view->GetClassName() == name) + return view; + } + return NULL; +} + gfx::Rect View::GetVisibleBounds() { if (!IsVisibleInRootView()) return gfx::Rect(); diff --git a/chrome/views/view.h b/chrome/views/view.h index 824eb3f..9d9a1f7 100644 --- a/chrome/views/view.h +++ b/chrome/views/view.h @@ -940,6 +940,10 @@ class View : public AcceleratorTarget { // subclass. The default implementation returns kViewClassName. virtual std::string GetClassName() const; + // Returns the first ancestor, starting at this, whose class name is |name|. + // Returns null if no ancestor has the class name |name|. + View* GetAncestorWithClassName(const std::string& name); + // Returns the visible bounds of the receiver in the receivers coordinate // system. // |