diff options
author | chrome-bot@google.com <chrome-bot@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-02 00:14:02 +0000 |
---|---|---|
committer | chrome-bot@google.com <chrome-bot@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-02 00:14:02 +0000 |
commit | 4523fd290e2915710025b46c15be689cb7638a00 (patch) | |
tree | 85ab2b1efd9ec09e08ac247128c8dda0735b4399 /chrome/browser/views | |
parent | bf0b51cbeef6ec8f7dc0d5fb46c76a739be5f84d (diff) | |
download | chromium_src-4523fd290e2915710025b46c15be689cb7638a00.zip chromium_src-4523fd290e2915710025b46c15be689cb7638a00.tar.gz chromium_src-4523fd290e2915710025b46c15be689cb7638a00.tar.bz2 |
Rolling back change 22245.
Too much red :-(
BUG=None
TEST=None
TBR=erikkay
Review URL: http://codereview.chromium.org/159763
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/extensions/extension_shelf.cc | 148 | ||||
-rw-r--r-- | chrome/browser/views/extensions/extension_shelf.h | 14 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 18 |
3 files changed, 47 insertions, 133 deletions
diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc index 3ba801c..77df55a 100644 --- a/chrome/browser/views/extensions/extension_shelf.cc +++ b/chrome/browser/views/extensions/extension_shelf.cc @@ -153,10 +153,6 @@ class ExtensionShelf::Toolstrip : public views::View, void DoHideShelfHandle(); void StopHandleTimer(); - // Expand / Collapse - void Expand(int height, const GURL& url); - void Collapse(const GURL& url); - // BrowserBubble::Delegate virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); @@ -258,8 +254,9 @@ void ExtensionShelf::Toolstrip::Paint(gfx::Canvas* canvas) { gfx::Size ExtensionShelf::Toolstrip::GetPreferredSize() { gfx::Size sz = title_->GetPreferredSize(); sz.set_width(std::max(view()->width(), sz.width())); - if (!expanded_) + if (!expanded_) { sz.Enlarge(2 + kHandlePadding * 2, kHandlePadding * 2); + } if (dragging_ || expanded_) { gfx::Size extension_size = view()->GetPreferredSize(); sz.Enlarge(0, extension_size.height() + 2); @@ -336,17 +333,33 @@ void ExtensionShelf::Toolstrip::OnMouseReleased(const views::MouseEvent& event, View::ConvertPointToView(NULL, shelf_, &loc); shelf_->DropExtension(this, loc, canceled); AttachToShelf(true); - } else if (!canceled) { + } else if (!canceled && + info_.mole.is_valid() && info_.toolstrip.is_valid()) { // Toggle mole to either expanded or collapsed. - // TODO(erikkay) If there's no valid URL in the manifest, should we - // post an event to the toolstrip in this case? + expanded_ = !expanded_; + view()->set_is_toolstrip(!expanded_); if (expanded_) { - if (info_.toolstrip.is_valid()) - shelf_->CollapseToolstrip(host_, info_.toolstrip); + host_->NavigateToURL(info_.mole); + StopHandleTimer(); + DetachFromShelf(false); + + gfx::Size extension_size = view()->GetPreferredSize(); + extension_size.set_height(info_.mole_height); + view()->SetPreferredSize(extension_size); + LayoutHandle(); } else { - if (info_.mole.is_valid()) - shelf_->ExpandToolstrip(host_, info_.mole, info_.mole_height); + gfx::Size extension_size = view()->GetPreferredSize(); + extension_size.set_height(kToolstripHeight); + view()->SetPreferredSize(extension_size); + + host_->NavigateToURL(info_.toolstrip); + AttachToShelf(false); } + + // This is to prevent flickering as the page loads and lays out. + // Once the navigation is finished, ExtensionView will wind up setting + // visibility to true. + view()->SetVisible(false); } } @@ -401,7 +414,6 @@ void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosing( } void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) { - DCHECK(handle_.get()); DCHECK(!placeholder_view_); if (browserDetach && handle_->attached()) handle_->DetachFromBrowser(); @@ -418,8 +430,6 @@ void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) { } void ExtensionShelf::Toolstrip::AttachToShelf(bool browserAttach) { - DCHECK(handle_.get()); - DCHECK(placeholder_view_); if (browserAttach && !handle_->attached()) handle_->AttachToBrowser(); @@ -463,56 +473,6 @@ void ExtensionShelf::Toolstrip::StopHandleTimer() { timer_factory_.RevokeAll(); } -void ExtensionShelf::Toolstrip::Expand(int height, const GURL& url) { - DCHECK(!expanded_); - - DoShowShelfHandle(); - - expanded_ = true; - view()->set_is_toolstrip(!expanded_); - - bool navigate = (!url.is_empty() && url != host_->GetURL()); - if (navigate) - host_->NavigateToURL(url); - - StopHandleTimer(); - DetachFromShelf(false); - - gfx::Size extension_size = view()->GetPreferredSize(); - extension_size.set_height(height); - view()->SetPreferredSize(extension_size); - LayoutHandle(); - - // This is to prevent flickering as the page loads and lays out. - // Once the navigation is finished, ExtensionView will wind up setting - // visibility to true. - if (navigate) - view()->SetVisible(false); -} - -void ExtensionShelf::Toolstrip::Collapse(const GURL& url) { - DCHECK(expanded_); - expanded_ = false; - view()->set_is_toolstrip(!expanded_); - - gfx::Size extension_size = view()->GetPreferredSize(); - extension_size.set_height(kToolstripHeight); - view()->SetPreferredSize(extension_size); - AttachToShelf(false); - - if (!url.is_empty() && url != host_->GetURL()) { - host_->NavigateToURL(url); - - // This is to prevent flickering as the page loads and lays out. - // Once the navigation is finished, ExtensionView will wind up setting - // visibility to true. - view()->SetVisible(false); - } - - // Must use the delay due to bug 18248. - HideShelfHandle(kHideDelayMs); -} - void ExtensionShelf::Toolstrip::ShowShelfHandle() { StopHandleTimer(); if (handle_visible()) @@ -540,21 +500,19 @@ void ExtensionShelf::Toolstrip::HideShelfHandle(int delay_ms) { //////////////////////////////////////////////////////////////////////////////// ExtensionShelf::ExtensionShelf(Browser* browser) - : model_(browser->extension_shelf_model()) { + : model_(new ExtensionShelfModel(browser)) { model_->AddObserver(this); LoadFromModel(); EnableCanvasFlippingForRTLUI(true); } ExtensionShelf::~ExtensionShelf() { - if (model_) { - int count = model_->count(); - for (int i = 0; i < count; ++i) { - delete ToolstripAtIndex(i); - model_->SetToolstripDataAt(i, NULL); - } - model_->RemoveObserver(this); + int count = model_->count(); + for (int i = 0; i < count; ++i) { + delete ToolstripAtIndex(i); + model_->SetToolstripDataAt(i, NULL); } + model_->RemoveObserver(this); } void ExtensionShelf::Paint(gfx::Canvas* canvas) { @@ -605,8 +563,6 @@ void ExtensionShelf::ChildPreferredSizeChanged(View* child) { void ExtensionShelf::Layout() { if (!GetParent()) return; - if (!model_) - return; int x = kLeftMargin; int y = kTopMargin; @@ -663,7 +619,7 @@ void ExtensionShelf::SetAccessibleName(const std::wstring& name) { void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, int index) { model_->SetToolstripDataAt(index, - new Toolstrip(this, host, model_->ToolstripAt(index).info)); + new Toolstrip(this, host, model_->ToolstripInfoAt(index))); bool had_views = GetChildViewCount() > 0; ExtensionView* view = host->view(); @@ -697,15 +653,7 @@ void ExtensionShelf::ToolstripMoved(ExtensionHost* host, int from_index, Layout(); } -void ExtensionShelf::ToolstripChanged(ExtensionShelfModel::iterator toolstrip) { - Toolstrip* t = static_cast<Toolstrip*>(toolstrip->data); - if (toolstrip->height > 0) { - if (!t->expanded()) { - t->Expand(toolstrip->height, toolstrip->url); - } - } else if (t->expanded()) { - t->Collapse(toolstrip->url); - } +void ExtensionShelf::ToolstripChangedAt(ExtensionHost* toolstrip, int index) { } void ExtensionShelf::ExtensionShelfEmpty() { @@ -718,16 +666,6 @@ void ExtensionShelf::ShelfModelReloaded() { LoadFromModel(); } -void ExtensionShelf::ShelfModelDeleting() { - int count = model_->count(); - for (int i = 0; i < count; ++i) { - delete ToolstripAtIndex(i); - model_->SetToolstripDataAt(i, NULL); - } - model_->RemoveObserver(this); - model_ = NULL; -} - void ExtensionShelf::OnExtensionMouseEvent(ExtensionView* view) { Toolstrip *toolstrip = ToolstripForView(view); if (toolstrip) @@ -751,23 +689,12 @@ void ExtensionShelf::DropExtension(Toolstrip* toolstrip, const gfx::Point& pt, } if (toolstrip == dest_toolstrip) return; - int from = model_->IndexOfHost(toolstrip->host()); - int to = model_->IndexOfHost(dest_toolstrip->host()); + int from = model_->IndexOfToolstrip(toolstrip->host()); + int to = model_->IndexOfToolstrip(dest_toolstrip->host()); DCHECK(from != to); model_->MoveToolstripAt(from, to); } -void ExtensionShelf::ExpandToolstrip(ExtensionHost* host, const GURL& url, - int height) { - ExtensionShelfModel::iterator toolstrip = model_->ToolstripForHost(host); - model_->ExpandToolstrip(toolstrip, url, height); -} - -void ExtensionShelf::CollapseToolstrip(ExtensionHost* host, const GURL& url) { - ExtensionShelfModel::iterator toolstrip = model_->ToolstripForHost(host); - model_->CollapseToolstrip(toolstrip, url); -} - void ExtensionShelf::InitBackground(gfx::Canvas* canvas, const SkRect& subset) { if (!background_.empty()) return; @@ -822,7 +749,7 @@ ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripAtX(int x) { } ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripAtIndex(int index) { - return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); + return static_cast<Toolstrip*>(model_->ToolstripDataAt(index)); } ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripForView( @@ -833,11 +760,12 @@ ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripForView( if (view == toolstrip->view()) return toolstrip; } + NOTREACHED(); return NULL; } void ExtensionShelf::LoadFromModel() { int count = model_->count(); for (int i = 0; i < count; ++i) - ToolstripInsertedAt(model_->ToolstripAt(i).host, i); + ToolstripInsertedAt(model_->ToolstripAt(i), i); } diff --git a/chrome/browser/views/extensions/extension_shelf.h b/chrome/browser/views/extensions/extension_shelf.h index e0dbe5d..57a0954 100644 --- a/chrome/browser/views/extensions/extension_shelf.h +++ b/chrome/browser/views/extensions/extension_shelf.h @@ -27,7 +27,7 @@ class ExtensionShelf : public views::View, virtual ~ExtensionShelf(); // Get the current model. - ExtensionShelfModel* model() { return model_; } + ExtensionShelfModel* model() { return model_.get(); } // View virtual void Paint(gfx::Canvas* canvas); @@ -50,10 +50,9 @@ class ExtensionShelf : public views::View, virtual void ToolstripMoved(ExtensionHost* toolstrip, int from_index, int to_index); - virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip); + virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index); virtual void ExtensionShelfEmpty(); virtual void ShelfModelReloaded(); - virtual void ShelfModelDeleting(); protected: // View @@ -67,13 +66,6 @@ class ExtensionShelf : public views::View, // Dragging toolstrips void DropExtension(Toolstrip* handle, const gfx::Point& pt, bool cancel); - // Expand the specified toolstrip, navigating to |url| if non-empty, - // and setting the |height|. - void ExpandToolstrip(ExtensionHost* host, const GURL& url, int height); - - // Collapse the specified toolstrip, navigating to |url| if non-empty. - void CollapseToolstrip(ExtensionHost* host, const GURL& url); - // Inits the background bitmap. void InitBackground(gfx::Canvas* canvas, const SkRect& subset); @@ -94,7 +86,7 @@ class ExtensionShelf : public views::View, SkBitmap background_; // The model representing the toolstrips on the shelf. - ExtensionShelfModel* model_; + scoped_ptr<ExtensionShelfModel> model_; // Storage of strings needed for accessibility. std::wstring accessible_name_; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 580ee77..c9a3155 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -599,13 +599,9 @@ void BrowserView::SetBounds(const gfx::Rect& bounds) { } void BrowserView::Close() { - // BrowserWindowClosing will usually cause the bubble to remove itself from - // the set, so we need to iterate in a way that's safe against deletion. - for (BubbleSet::iterator i = browser_bubbles_.begin(); - i != browser_bubbles_.end();) { - BubbleSet::iterator bubble = i++; + BubbleSet::iterator bubble = browser_bubbles_.begin(); + for (; bubble != browser_bubbles_.end(); ++bubble) (*bubble)->BrowserWindowClosing(); - } frame_->GetWindow()->Close(); } @@ -1494,12 +1490,10 @@ void BrowserView::Init() { status_bubble_.reset(new StatusBubbleViews(GetWidget())); - if (browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF)) { - extension_shelf_ = new ExtensionShelf(browser_.get()); - extension_shelf_-> - SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_EXTENSIONS)); - AddChildView(extension_shelf_); - } + extension_shelf_ = new ExtensionShelf(browser_.get()); + extension_shelf_-> + SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_EXTENSIONS)); + AddChildView(extension_shelf_); #if defined(OS_WIN) InitSystemMenu(); |