diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 19:48:08 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 19:48:08 +0000 |
commit | 0666aef37e02188ef4b4c8890c08c5665970d54e (patch) | |
tree | ecc6f3d21eccb33040849c37d15b28a8d65f8fa1 | |
parent | 0582493ed8a6aa530c16acffb2cf2bae4bfd955f (diff) | |
download | chromium_src-0666aef37e02188ef4b4c8890c08c5665970d54e.zip chromium_src-0666aef37e02188ef4b4c8890c08c5665970d54e.tar.gz chromium_src-0666aef37e02188ef4b4c8890c08c5665970d54e.tar.bz2 |
Propagate intrinsic width notification over IPC in all cases (not just extensions) to the TabContentsView. Enable the zoom button on Mac to utilize it. Ensure we only send the IPC notification when the value changes, as WebCore tends to over-report that it has changed. Fix const-ness in delegate API where it's not necessary.
Review URL: http://codereview.chromium.org/115138
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15988 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 5 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_host.h | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host_delegate.h | 6 | ||||
-rw-r--r-- | chrome/browser/tab_contents/interstitial_page.cc | 5 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view.cc | 11 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view.h | 14 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.h | 4 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.mm | 8 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 5 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 32 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 8 |
15 files changed, 93 insertions, 20 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 0f6ef71..3dba768 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -213,8 +213,6 @@ willPositionSheet:(NSWindow *)sheet // regardless. - (NSRect)windowWillUseStandardFrame:(NSWindow*)window defaultFrame:(NSRect)frame { -#if 0 -// TODO(pinkerton): this is part of another CL which is out for review. const int kMinimumIntrinsicWidth = 700; const int kScrollbarWidth = 16; const int kSpaceForIcons = 50; @@ -224,12 +222,11 @@ willPositionSheet:(NSWindow *)sheet TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents(); if (contents) { - int intrinsicWidth = contents->preferred_width() + kScrollbarWidth; + int intrinsicWidth = contents->view()->preferred_width() + kScrollbarWidth; int tempWidth = std::max(intrinsicWidth, kMinimumIntrinsicWidth); frame.size.width = std::min(tempWidth, kMaxWidth); frame.size.height = screenSize.height; } -#endif return frame; } diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 5f91ba1..e2f202a 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -49,7 +49,7 @@ void ExtensionHost::CreateRenderView(const GURL& url, render_view_host_->NavigateToURL(url); } -void ExtensionHost::DidContentsPreferredWidthChange(const int pref_width) { +void ExtensionHost::UpdatePreferredWidth(int pref_width) { if (view_) view_->DidContentsPreferredWidthChange(pref_width); } diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index 8c5a8cd..d8e9a50 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -43,7 +43,6 @@ class ExtensionHost : public RenderViewHostDelegate, // TODO(mpcomplete): GetProfile is unused. virtual Profile* GetProfile() const { return NULL; } virtual const GURL& GetURL() const { return url_; } - virtual void DidContentsPreferredWidthChange(const int pref_width); virtual WebPreferences GetWebkitPrefs(); virtual void RunJavaScriptMessage( const std::wstring& message, @@ -73,6 +72,7 @@ class ExtensionHost : public RenderViewHostDelegate, virtual void UpdateDragCursor(bool is_drop_target); virtual void TakeFocus(bool reverse); virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); + virtual void UpdatePreferredWidth(int pref_width); private: // ExtensionFunctionDispatcher::Delegate diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 0f3141f..09737bb 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -1081,8 +1081,11 @@ void RenderViewHost::OnMsgOpenURL(const GURL& url, delegate_->RequestOpenURL(validated_url, referrer, disposition); } -void RenderViewHost::OnMsgDidContentsPreferredWidthChange(const int pref_width) { - delegate_->DidContentsPreferredWidthChange(pref_width); +void RenderViewHost::OnMsgDidContentsPreferredWidthChange(int pref_width) { + RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); + if (!view) + return; + view->UpdatePreferredWidth(pref_width); } void RenderViewHost::OnMsgDomOperationResponse( diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 25ff89b..4421aab 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -482,7 +482,7 @@ class RenderViewHost : public RenderWidgetHost { void OnMsgContextMenu(const ContextMenuParams& params); void OnMsgOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition); - void OnMsgDidContentsPreferredWidthChange(const int pref_width); + void OnMsgDidContentsPreferredWidthChange(int pref_width); void OnMsgDomOperationResponse(const std::string& json_string, int automation_id); void OnMsgDOMUISend(const std::string& message, diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 88ba027..14c1337 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -117,6 +117,9 @@ class RenderViewHostDelegate { // specified events. This gives an opportunity to the browser to process the // event (used for keyboard shortcuts). virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) = 0; + + // The content's intrinsic width (prefWidth) changed. + virtual void UpdatePreferredWidth(int pref_width) = 0; }; // Interface for saving web pages. @@ -253,9 +256,6 @@ class RenderViewHostDelegate { bool errored, const SkBitmap& image) { } - // The content's intrinsic width (prefWidth) changed. - virtual void DidContentsPreferredWidthChange(const int pref_width) { } - // The page wants to open a URL with the specified disposition. virtual void RequestOpenURL(const GURL& url, const GURL& referrer, diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index 0dbe26a..04afbbc 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -90,6 +90,7 @@ class InterstitialPage::InterstitialPageRVHViewDelegate const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update); + virtual void UpdatePreferredWidth(int pref_width); private: InterstitialPage* interstitial_page_; @@ -516,6 +517,10 @@ void InterstitialPage::InterstitialPageRVHViewDelegate::UpdateDragCursor( NOTREACHED() << "InterstitialPage does not support dragging yet."; } +void InterstitialPage::InterstitialPageRVHViewDelegate::UpdatePreferredWidth( + int pref_width) { +} + void InterstitialPage::InterstitialPageRVHViewDelegate::TakeFocus( bool reverse) { if (interstitial_page_->tab() && interstitial_page_->tab()->GetViewDelegate()) diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 5bc2cacd..d253dc9 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1626,6 +1626,8 @@ void TabContents::RenderViewCreated(RenderViewHost* render_view_host) { render_view_host->Send( new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); } + + view()->RenderViewCreated(render_view_host); } void TabContents::RenderViewReady(RenderViewHost* rvh) { diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/chrome/browser/tab_contents/tab_contents_view.cc index 402876d..78d084a 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/chrome/browser/tab_contents/tab_contents_view.cc @@ -11,7 +11,8 @@ #include "chrome/browser/tab_contents/tab_contents_delegate.h" TabContentsView::TabContentsView(TabContents* tab_contents) - : tab_contents_(tab_contents) { + : tab_contents_(tab_contents), + preferred_width_(0) { } void TabContentsView::CreateView() { @@ -21,6 +22,14 @@ void TabContentsView::RenderWidgetHostDestroyed(RenderWidgetHost* host) { delegate_view_helper_.RenderWidgetHostDestroyed(host); } +void TabContentsView::RenderViewCreated(RenderViewHost* host) { + // Default implementation does nothing. Platforms may override. +} + +void TabContentsView::UpdatePreferredWidth(int pref_width) { + preferred_width_ = pref_width; +} + void TabContentsView::CreateNewWindow(int route_id, base::WaitableEvent* modal_dialog_event) { delegate_view_helper_.CreateNewWindow(route_id, modal_dialog_event, diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h index 2af4902..c5868b0 100644 --- a/chrome/browser/tab_contents/tab_contents_view.h +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -110,6 +110,11 @@ class TabContentsView : public RenderViewHostDelegate::View { // RenderWidgetHost is deleted. Removes |host| from internal maps. void RenderWidgetHostDestroyed(RenderWidgetHost* host); + // Invoked when the TabContents is notified that the RenderView has been + // fully created. The default implementation does nothing; override + // for platform-specific behavior is needed. + virtual void RenderViewCreated(RenderViewHost* host); + // Sets focus to the native widget for this tab. virtual void Focus() = 0; @@ -124,6 +129,12 @@ class TabContentsView : public RenderViewHostDelegate::View { // invoked, SetInitialFocus is invoked. virtual void RestoreFocus() = 0; + // Set and return the content's intrinsic width. + virtual void UpdatePreferredWidth(int pref_width); + int preferred_width() const { + return preferred_width_; + } + protected: TabContentsView() {} // Abstract interface. @@ -171,6 +182,9 @@ class TabContentsView : public RenderViewHostDelegate::View { typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews; PendingWidgetViews pending_widget_views_; + // The page content's intrinsic width. + int preferred_width_; + DISALLOW_COPY_AND_ASSIGN(TabContentsView); }; diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.h b/chrome/browser/tab_contents/tab_contents_view_mac.h index 0fd3c89..8259316 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.h +++ b/chrome/browser/tab_contents/tab_contents_view_mac.h @@ -46,6 +46,7 @@ class TabContentsViewMac : public TabContentsView, virtual gfx::NativeWindow GetTopLevelNativeWindow() const; virtual void GetContainerBounds(gfx::Rect* out) const; virtual void OnContentsDestroy(); + virtual void RenderViewCreated(RenderViewHost* host); virtual void SetPageTitle(const std::wstring& title); virtual void Invalidate(); virtual void SizeContents(const gfx::Size& size); @@ -84,6 +85,9 @@ class TabContentsViewMac : public TabContentsView, // visible. scoped_nsobject<SadTabView> sad_tab_; + // The page content's intrinsic width. + int preferred_width_; + DISALLOW_COPY_AND_ASSIGN(TabContentsViewMac); }; diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 662dd42..d0d814d4 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -12,6 +12,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_type.h" #include "chrome/common/notification_service.h" +#include "chrome/common/render_messages.h" #include "chrome/common/temp_scaffolding_stubs.h" @@ -90,6 +91,13 @@ void TabContentsViewMac::StartDragging(const WebDropData& drop_data) { void TabContentsViewMac::OnContentsDestroy() { } +void TabContentsViewMac::RenderViewCreated(RenderViewHost* host) { + // We want updates whenever the intrinsic width of the webpage + // changes. Put the RenderView into that mode. + int routing_id = host->routing_id(); + host->Send(new ViewMsg_EnableIntrinsicWidthChangedMode(routing_id)); +} + void TabContentsViewMac::SetPageTitle(const std::wstring& title) { // Meaningless on the Mac; widgets don't have a "title" attribute } diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index c413dbf..fb94641 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -582,6 +582,11 @@ IPC_BEGIN_MESSAGES(View) // processing. This is used because the renderer keeps a temporary cache of // the widget position while these asynchronous operations are in progress. IPC_MESSAGE_ROUTED0(ViewMsg_Move_ACK) + + // Used to instruct the RenderView to send back updates to the intrinsic + // width. + IPC_MESSAGE_ROUTED0(ViewMsg_EnableIntrinsicWidthChangedMode) + IPC_END_MESSAGES(View) diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index e4669ca..a38a710 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -200,7 +200,9 @@ RenderView::RenderView(RenderThreadBase* render_thread) decrement_shared_popup_at_destruction_(false), form_field_autofill_request_id_(0), popup_notification_visible_(false), - delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync) { + delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync), + preferred_width_(0), + send_preferred_width_changes_(false) { } RenderView::~RenderView() { @@ -431,6 +433,8 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) + IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode, + OnEnableIntrinsicWidthChangedMode) // Have the super handle all other messages. IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) @@ -1926,13 +1930,23 @@ void RenderView::OpenURL(WebView* webview, const GURL& url, void RenderView::DidContentsSizeChange(WebWidget* webwidget, int new_width, int new_height) { - // TODO(rafaelw): This is a temporary solution. Only the ExtensionView wants - // this notification at the moment. It isn't clean to test for ExtensionView - // by examining the enabled_bindings. This needs to be generalized as it - // becomes clear what extension toolbars need. - if (BindingsPolicy::is_extension_enabled(enabled_bindings_)) { + // We don't always want to send the change messages over IPC, only if we've + // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode| + // message. + // TODO(rafaelw): Figure out where the best place to set this for extensions + // is. It isn't clean to test for ExtensionView by examining the + // enabled_bindings. This needs to be generalized as it becomes clear what + // extension toolbars need. + if (BindingsPolicy::is_extension_enabled(enabled_bindings_) || + send_preferred_width_changes_) { + // WebCore likes to tell us things have changed even when they haven't, so + // cache the width and only send the IPC message when we're sure the + // width is different. int width = webview()->GetMainFrame()->GetContentsPreferredWidth(); - Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width)); + if (width != preferred_width_) { + Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width)); + preferred_width_ = width; + } } } @@ -2720,6 +2734,10 @@ void RenderView::OnEnableViewSourceMode() { main_frame->SetInViewSourceMode(true); } +void RenderView::OnEnableIntrinsicWidthChangedMode() { + send_preferred_width_changes_ = true; +} + void RenderView::OnUpdateBackForwardListCount(int back_list_count, int forward_list_count) { history_back_list_count_ = back_list_count; diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 678dbb5..e58a641 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -541,6 +541,7 @@ class RenderView : public RenderWidget, void OnInstallMissingPlugin(); void OnFileChooserResponse(const std::vector<FilePath>& file_names); void OnEnableViewSourceMode(); + void OnEnableIntrinsicWidthChangedMode(); void OnUpdateBackForwardListCount(int back_list_count, int forward_list_count); void OnGetAccessibilityInfo( @@ -799,6 +800,13 @@ class RenderView : public RenderWidget, // it's for the selection clipboard. std::string selection_text_; + // Cache the preferred width of the page in order to prevent sending the IPC + // when layout() recomputes it but it doesn't actually change. + int preferred_width_; + + // If true, we send IPC messages when the preferred width changes. + bool send_preferred_width_changes_; + DISALLOW_COPY_AND_ASSIGN(RenderView); }; |