From 07442307cd72bbe129cb87887438e82f146c0773 Mon Sep 17 00:00:00 2001 From: "erikkay@chromium.org" Date: Fri, 18 Sep 2009 22:29:32 +0000 Subject: Change the view mode when switching between moles and toolstrips, and propogate this into the class of the document element so that it's possible to use CSS rules to control the display of your toolstrip/mole. BUG=21939,15494 TEST=run the Mappy extension and verify it can open and close Review URL: http://codereview.chromium.org/208020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26635 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser_resources.grd | 2 +- chrome/browser/extensions/extension_host.cc | 55 +++++-------- chrome/browser/extensions/extension_host.h | 8 +- chrome/browser/extensions/extension_shelf_model.cc | 2 + chrome/browser/renderer_host/render_view_host.cc | 4 + chrome/browser/renderer_host/render_view_host.h | 3 + chrome/browser/resources/extensions_toolstrip.css | 95 ---------------------- .../resources/extensions_toolstrip_theme.css | 8 ++ chrome/browser/views/extensions/extension_shelf.cc | 2 +- chrome/browser/views/extensions/extension_view.cc | 8 +- chrome/browser/views/extensions/extension_view.h | 6 +- 11 files changed, 51 insertions(+), 142 deletions(-) delete mode 100644 chrome/browser/resources/extensions_toolstrip.css create mode 100644 chrome/browser/resources/extensions_toolstrip_theme.css (limited to 'chrome/browser') diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 788d62d..7e07058 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -41,7 +41,7 @@ without changes to the corresponding grd file. fb03 --> - + diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index f8503f3..a23c886 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -180,32 +180,12 @@ void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, new ExtensionFunctionDispatcher(render_view_host_, this, url_)); } -void ExtensionHost::InsertCssIfToolstrip() { - - // TODO(erikkay): Make these ifdefs go away -- http://crbug.com/21939 -#if defined(TOOLKIT_VIEWS) - ExtensionView* view = view_.get(); - if (!view) - return; - if (!view->is_toolstrip()) { - // No CSS injecting currently, but call SetDidInsertCSS to tell the view - // that it's OK to display. - view->SetDidInsertCSS(true); - return; - } -#elif defined(OS_LINUX) || defined(OS_MACOSX) -#if defined(OS_LINUX) - ExtensionViewGtk* view = view_.get(); -#else - ExtensionViewMac* view = view_.get(); -#endif - if (!view || !view->is_toolstrip()) - return; -#endif +void ExtensionHost::InsertThemeCSS() { + DCHECK(!is_background_page()); static const base::StringPiece toolstrip_css( ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_EXTENSIONS_TOOLSTRIP_CSS)); + IDR_EXTENSIONS_TOOLSTRIP_THEME_CSS)); std::string css = toolstrip_css.as_string(); ThemeProvider* theme_provider = @@ -225,16 +205,12 @@ void ExtensionHost::InsertCssIfToolstrip() { pos = css.find(kToolstripTextColorSubstitution); } - // TODO(erikkay) this injection should really happen in the renderer. - // When the Jerry's view type change lands, investigate moving this there. - // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips // to blend in with the chrome UI. - render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripDefaultCss"); + render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripThemeCSS"); } void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { - InsertCssIfToolstrip(); if (!did_stop_loading_) { NotificationService::current()->Notify( NotificationType::EXTENSION_HOST_DID_STOP_LOADING, @@ -242,12 +218,21 @@ void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { Details(this)); did_stop_loading_ = true; } + if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP || + extension_host_type_ == ViewType::EXTENSION_MOLE) { +#if defined(TOOLKIT_VIEWS) + if (view_.get()) + view_->DidStopLoading(); +#endif + } } void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { document_element_available_ = true; if (is_background_page()) extension_->SetBackgroundPageReady(); + else + InsertThemeCSS(); } void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, @@ -278,13 +263,6 @@ void ExtensionHost::ProcessDOMUIMessage(const std::string& message, } } -void ExtensionHost::DidInsertCSS() { -#if defined(TOOLKIT_VIEWS) - if (view_.get()) - view_->SetDidInsertCSS(true); -#endif -} - RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() { return this; } @@ -391,6 +369,13 @@ Browser* ExtensionHost::GetBrowser() { return browser; } +void ExtensionHost::SetRenderViewType(ViewType::Type type) { + DCHECK(type == ViewType::EXTENSION_MOLE || + type == ViewType::EXTENSION_TOOLSTRIP); + extension_host_type_ = type; + render_view_host()->ViewTypeChanged(extension_host_type_); +} + ViewType::Type ExtensionHost::GetRenderViewType() const { return extension_host_type_; } diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index 49a75f1..3b3d64e 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -69,6 +69,9 @@ class ExtensionHost : public RenderViewHostDelegate, return document_element_available_; } + // Sets the the ViewType of this host (e.g. mole, toolstrip). + void SetRenderViewType(ViewType::Type type); + // Returns true if the render view is initialized and didn't crash. bool IsRenderViewLive() const; @@ -80,8 +83,8 @@ class ExtensionHost : public RenderViewHostDelegate, // Sets |url_| and navigates |render_view_host_|. void NavigateToURL(const GURL& url); - // Insert the CSS for a toolstrip. - void InsertCssIfToolstrip(); + // Insert the theme CSS for a toolstrip/mole. + void InsertThemeCSS(); // RenderViewHostDelegate implementation. virtual RenderViewHostDelegate::View* GetViewDelegate(); @@ -106,7 +109,6 @@ class ExtensionHost : public RenderViewHostDelegate, const int flags, IPC::Message* reply_msg, bool* did_suppress_message); - virtual void DidInsertCSS(); // RenderViewHostDelegate::View virtual void CreateNewWindow(int route_id, diff --git a/chrome/browser/extensions/extension_shelf_model.cc b/chrome/browser/extensions/extension_shelf_model.cc index 5a6db01..10b56b2 100644 --- a/chrome/browser/extensions/extension_shelf_model.cc +++ b/chrome/browser/extensions/extension_shelf_model.cc @@ -138,6 +138,7 @@ void ExtensionShelfModel::ExpandToolstrip(iterator toolstrip, ToolstripEventRouter::OnToolstripExpanded(browser_->profile(), routing_id, url, height); + toolstrip->host->SetRenderViewType(ViewType::EXTENSION_MOLE); } void ExtensionShelfModel::CollapseToolstrip(iterator toolstrip, @@ -152,6 +153,7 @@ void ExtensionShelfModel::CollapseToolstrip(iterator toolstrip, ToolstripEventRouter::OnToolstripCollapsed(browser_->profile(), routing_id, url); + toolstrip->host->SetRenderViewType(ViewType::EXTENSION_TOOLSTRIP); } void ExtensionShelfModel::Observe(NotificationType type, diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 63cc15e..41a30f2 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -1660,6 +1660,10 @@ void RenderViewHost::BlockExtensionRequest(int request_id) { "Access to extension API denied."); } +void RenderViewHost::ViewTypeChanged(ViewType::Type type) { + Send(new ViewMsg_NotifyRenderViewType(routing_id(), type)); +} + void RenderViewHost::OnExtensionPostMessage( int port_id, const std::string& message) { if (process()->profile()->GetExtensionMessageService()) { diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index b7f2d86..cbf0f73 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -436,6 +436,9 @@ class RenderViewHost : public RenderWidgetHost, // permission. void BlockExtensionRequest(int request_id); + // Notify the renderer that its view type has changed. + void ViewTypeChanged(ViewType::Type type); + void SignalModalDialogEvent(); void ResetModalDialogEvent(); diff --git a/chrome/browser/resources/extensions_toolstrip.css b/chrome/browser/resources/extensions_toolstrip.css deleted file mode 100644 index cb23825..0000000 --- a/chrome/browser/resources/extensions_toolstrip.css +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Body styles. This makes the toolstrip layout fit in with the Windows - * bookmarkbar. Note that the background is provided separately, by - * RenderWidget. - */ -body { - display:-webkit-box; - -webkit-box-orient:horizontal; - -webkit-box-align:center; - white-space:nowrap; - overflow: hidden; - margin: 0; - padding:0; - font: menu; - color: $TEXT_COLOR$; - -webkit-user-select:none; - cursor:default; -} - -/** - * This, combined with -webkit-box-align:center on body, makes content inside - * the body tag center itself vertically by default. - */ -body>* { - display:-webkit-box; -} - -/** - * Set display property of