diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-26 00:11:42 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-26 00:11:42 +0000 |
commit | bbc94554729407f821d4a60828c5758a112f042a (patch) | |
tree | fa92103aa16e6ff04e90206c6ac99710c3c2d7ca /chrome/browser/views | |
parent | 4289d9b66a1453aad1115f6ede0007faab22d6d4 (diff) | |
download | chromium_src-bbc94554729407f821d4a60828c5758a112f042a.zip chromium_src-bbc94554729407f821d4a60828c5758a112f042a.tar.gz chromium_src-bbc94554729407f821d4a60828c5758a112f042a.tar.bz2 |
add mole info to toolstrip definition and enable moles
Review URL: http://codereview.chromium.org/159202
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/browser_bubble.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/browser_bubble.h | 7 | ||||
-rw-r--r-- | chrome/browser/views/extensions/extension_shelf.cc | 100 | ||||
-rw-r--r-- | chrome/browser/views/extensions/extension_view.cc | 9 | ||||
-rw-r--r-- | chrome/browser/views/extensions/extension_view.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 9 |
6 files changed, 90 insertions, 47 deletions
diff --git a/chrome/browser/views/browser_bubble.cc b/chrome/browser/views/browser_bubble.cc index 15c45a6..de6959b 100644 --- a/chrome/browser/views/browser_bubble.cc +++ b/chrome/browser/views/browser_bubble.cc @@ -62,11 +62,13 @@ void BrowserBubble::BrowserWindowMoved() { delegate_->BubbleBrowserWindowMoved(this); else Hide(); + if (visible_) + Reposition(); } -void BrowserBubble::BrowserWindowClosed() { +void BrowserBubble::BrowserWindowClosing() { if (delegate_) - delegate_->BubbleBrowserWindowClosed(this); + delegate_->BubbleBrowserWindowClosing(this); else Hide(); } diff --git a/chrome/browser/views/browser_bubble.h b/chrome/browser/views/browser_bubble.h index 13317f55..03e9377 100644 --- a/chrome/browser/views/browser_bubble.h +++ b/chrome/browser/views/browser_bubble.h @@ -20,7 +20,10 @@ class BrowserBubble { public: // Called when the Browser Window that this bubble is attached to moves. virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble) = 0; - virtual void BubbleBrowserWindowClosed(BrowserBubble* bubble) = 0; + + // Called with the Browser Window that this bubble is attached to is + // about to close. + virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble) = 0; }; // Note that the bubble will size itself to the preferred size of |view|. @@ -48,7 +51,7 @@ class BrowserBubble { // Notifications from BrowserView. // With no delegate, both of these default to Hiding the bubble. virtual void BrowserWindowMoved(); - virtual void BrowserWindowClosed(); + virtual void BrowserWindowClosing(); // Show or hide the bubble. void Show(); diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc index 121ac79..77df55a 100644 --- a/chrome/browser/views/extensions/extension_shelf.cc +++ b/chrome/browser/views/extensions/extension_shelf.cc @@ -41,6 +41,9 @@ static const int kToolstripDividerWidth = 2; // Preferred height of the ExtensionShelf. static const int kShelfHeight = 29; +// Height of the toolstrip within the shelf. +static const int kToolstripHeight = kShelfHeight - (kTopMargin + kBottomMargin); + // Colors for the ExtensionShelf. static const SkColor kBackgroundColor = SkColorSetRGB(230, 237, 244); static const SkColor kBorderColor = SkColorSetRGB(201, 212, 225); @@ -69,14 +72,19 @@ static const int kHideDelayMs = 500; // is being dragged or moved. // TODO(erikkay) this should draw a dimmed out version of the toolstrip. class ExtensionShelf::PlaceholderView : public views::View { -public: + public: PlaceholderView() {} + void SetWidth(int width) { + SetBounds(x(), y(), width, height()); + PreferredSizeChanged(); + } + // ExtensionShelf resizes its views to their preferred size at layout, // so just always prefer the current size. gfx::Size GetPreferredSize() { return size(); } -private: + private: DISALLOW_COPY_AND_ASSIGN(PlaceholderView); }; @@ -86,7 +94,8 @@ private: class ExtensionShelf::Toolstrip : public views::View, public BrowserBubble::Delegate { public: - Toolstrip(ExtensionShelf* shelf, ExtensionHost* host); + Toolstrip(ExtensionShelf* shelf, ExtensionHost* host, + const Extension::ToolstripInfo& info); virtual ~Toolstrip(); // View @@ -146,12 +155,15 @@ class ExtensionShelf::Toolstrip : public views::View, // BrowserBubble::Delegate virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); - virtual void BubbleBrowserWindowClosed(BrowserBubble* bubble); + virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); private: // The actual renderer that this toolstrip contains. ExtensionHost* host_; + // Manifest definition of this toolstrip. + Extension::ToolstripInfo info_; + // The handle is a BrowserBubble so that it can exist as an independent, // floating window. It also acts as the container for the ExtensionView when // it's being dragged. @@ -184,8 +196,10 @@ class ExtensionShelf::Toolstrip : public views::View, }; ExtensionShelf::Toolstrip::Toolstrip(ExtensionShelf* shelf, - ExtensionHost* host) + ExtensionHost* host, + const Extension::ToolstripInfo& info) : host_(host), + info_(info), shelf_(shelf), placeholder_view_(NULL), dragging_(false), @@ -239,21 +253,13 @@ void ExtensionShelf::Toolstrip::Paint(gfx::Canvas* canvas) { gfx::Size ExtensionShelf::Toolstrip::GetPreferredSize() { gfx::Size sz = title_->GetPreferredSize(); - int width = std::max(view()->width() + 2, sz.width()); - sz.set_width(width); - sz.Enlarge(kHandlePadding * 2, kHandlePadding * 2); - if (dragging_) { + sz.set_width(std::max(view()->width(), sz.width())); + 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); - } else if (expanded_) { - // TODO(erikkay) these sizes are a temporary hack until we can get the - // size from the extension itself. - const int tempHeight = 200; - const int tempWidth = 400; - int width = std::max(sz.width(), tempWidth); - sz.set_width(width); - gfx::Size extension_size = view()->GetPreferredSize(); - sz.Enlarge(0, extension_size.height() + 2 + tempHeight); } return sz; } @@ -315,7 +321,9 @@ bool ExtensionShelf::Toolstrip::OnMouseDragged(const views::MouseEvent& event) { void ExtensionShelf::Toolstrip::OnMouseReleased(const views::MouseEvent& event, bool canceled) { + StopHandleTimer(); if (dragging_) { + // Drop the toolstrip roughly where it is now. views::View::OnMouseReleased(event, canceled); dragging_ = false; // |this| and |shelf_| are in different view hierarchies, so we need to @@ -325,18 +333,33 @@ void ExtensionShelf::Toolstrip::OnMouseReleased(const views::MouseEvent& event, View::ConvertPointToView(NULL, shelf_, &loc); shelf_->DropExtension(this, loc, canceled); AttachToShelf(true); - } else { -#if 0 - // TODO(erikkay) implementation currently in progress + } else if (!canceled && + info_.mole.is_valid() && info_.toolstrip.is_valid()) { + // Toggle mole to either expanded or collapsed. expanded_ = !expanded_; + view()->set_is_toolstrip(!expanded_); if (expanded_) { + 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 { + gfx::Size extension_size = view()->GetPreferredSize(); + extension_size.set_height(kToolstripHeight); + view()->SetPreferredSize(extension_size); + + host_->NavigateToURL(info_.toolstrip); AttachToShelf(false); } -#endif + + // 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); } } @@ -357,7 +380,7 @@ void ExtensionShelf::Toolstrip::LayoutHandle() { int handle_width = std::max(view()->width(), width()); gfx::Point origin(-kToolstripPadding, -(height() + kToolstripPadding - 1)); if (expanded_) { - origin.set_y(-(height() + kToolstripPadding - 1)); + origin.set_y(GetShelfView()->height() - height()); views::View::ConvertPointToView(GetShelfView(), shelf_->GetRootView(), &origin); } else { @@ -369,18 +392,25 @@ void ExtensionShelf::Toolstrip::LayoutHandle() { } void ExtensionShelf::Toolstrip::ChildPreferredSizeChanged(View* child) { - if (child == view()) + if (child == view()) { child->SizeToPreferredSize(); + Layout(); + if (expanded_) { + LayoutHandle(); + placeholder_view_->SetWidth(child->width()); + shelf_->Layout(); + } + } } -void ExtensionShelf::Toolstrip::BubbleBrowserWindowMoved(BrowserBubble* bubble) -{ +void ExtensionShelf::Toolstrip::BubbleBrowserWindowMoved( + BrowserBubble* bubble) { HideShelfHandle(0); } -void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosed(BrowserBubble* bubble) -{ - HideShelfHandle(0); +void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosing( + BrowserBubble* bubble) { + DoHideShelfHandle(); } void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) { @@ -429,12 +459,13 @@ void ExtensionShelf::Toolstrip::DoShowShelfHandle() { } void ExtensionShelf::Toolstrip::DoHideShelfHandle() { - if (!handle_visible() || dragging_ || expanded_) + if (!handle_visible()) return; handle_->Hide(); if (handle_->attached()) handle_->DetachFromBrowser(); handle_.reset(NULL); + shelf_->Layout(); } void ExtensionShelf::Toolstrip::StopHandleTimer() { @@ -526,8 +557,7 @@ void ExtensionShelf::ChildPreferredSizeChanged(View* child) { Toolstrip *toolstrip = ToolstripForView(static_cast<ExtensionView*>(child)); if (!toolstrip) return; - if (!toolstrip->handle_visible()) - Layout(); + Layout(); } void ExtensionShelf::Layout() { @@ -586,8 +616,10 @@ void ExtensionShelf::SetAccessibleName(const std::wstring& name) { accessible_name_.assign(name); } -void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, int index) { - model_->SetToolstripDataAt(index, new Toolstrip(this, host)); +void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, + int index) { + model_->SetToolstripDataAt(index, + new Toolstrip(this, host, model_->ToolstripInfoAt(index))); bool had_views = GetChildViewCount() > 0; ExtensionView* view = host->view(); diff --git a/chrome/browser/views/extensions/extension_view.cc b/chrome/browser/views/extensions/extension_view.cc index 120fb3c..1518567 100644 --- a/chrome/browser/views/extensions/extension_view.cc +++ b/chrome/browser/views/extensions/extension_view.cc @@ -15,7 +15,7 @@ ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) : host_(host), browser_(browser), initialized_(false), pending_preferred_width_(0), container_(NULL), - did_insert_css_(false), is_clipped_(false) { + did_insert_css_(false), is_clipped_(false), is_toolstrip_(true) { host_->set_view(this); } @@ -127,10 +127,13 @@ void ExtensionView::SetBackground(const SkBitmap& background) { void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) { // Don't actually do anything with this information until we have been shown. // Size changes will not be honored by lower layers while we are hidden. + gfx::Size preferred_size = GetPreferredSize(); if (!IsVisible()) { pending_preferred_width_ = pref_width; - } else if (pref_width > 0 && pref_width != GetPreferredSize().width()) { - SetPreferredSize(gfx::Size(pref_width, height())); + } else if (pref_width > 0 && pref_width != preferred_size.width()) { + if (preferred_size.height() == 0) + preferred_size.set_height(height()); + SetPreferredSize(gfx::Size(pref_width, preferred_size.height())); } } diff --git a/chrome/browser/views/extensions/extension_view.h b/chrome/browser/views/extensions/extension_view.h index de34aa5..df3ca2d 100644 --- a/chrome/browser/views/extensions/extension_view.h +++ b/chrome/browser/views/extensions/extension_view.h @@ -8,7 +8,6 @@ #include "build/build_config.h" #include "base/scoped_ptr.h" -#include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" #include "views/controls/native/native_view_host.h" @@ -39,6 +38,8 @@ class ExtensionView : public views::NativeViewHost { RenderViewHost* render_view_host() const; void SetDidInsertCSS(bool did_insert); void set_is_clipped(bool is_clipped) { is_clipped_ = is_clipped; } + bool is_toolstrip() const { return is_toolstrip_; } + void set_is_toolstrip(bool is) { is_toolstrip_ = is; } // Notification from ExtensionHost. void DidContentsPreferredWidthChange(const int pref_width); @@ -103,6 +104,9 @@ class ExtensionView : public views::NativeViewHost { // Whether this extension view is clipped. bool is_clipped_; + // Whether this view is currently displaying in toolstrip mode. + bool is_toolstrip_; + DISALLOW_COPY_AND_ASSIGN(ExtensionView); }; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 24e29da..6d59587 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -602,12 +602,11 @@ void BrowserView::SetBounds(const gfx::Rect& bounds) { } void BrowserView::Close() { - frame_->GetWindow()->Close(); - BubbleSet::iterator bubble = browser_bubbles_.begin(); - for (; bubble != browser_bubbles_.end(); ++bubble) { - (*bubble)->BrowserWindowClosed(); - } + for (; bubble != browser_bubbles_.end(); ++bubble) + (*bubble)->BrowserWindowClosing(); + + frame_->GetWindow()->Close(); } void BrowserView::Activate() { |