diff options
-rw-r--r-- | chrome/browser/cocoa/extension_view_mac.h | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/extension_view_mac.mm | 16 | ||||
-rw-r--r-- | chrome/browser/cocoa/extensions/extension_popup_controller.mm | 28 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_host.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_host.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_view_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 5 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 22 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 13 |
9 files changed, 95 insertions, 18 deletions
diff --git a/chrome/browser/cocoa/extension_view_mac.h b/chrome/browser/cocoa/extension_view_mac.h index 4ce4c13..5fb0f54 100644 --- a/chrome/browser/cocoa/extension_view_mac.h +++ b/chrome/browser/cocoa/extension_view_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -49,6 +49,15 @@ class ExtensionViewMac { // connection. void RenderViewCreated(); + // The minimum/maximum dimensions of the popup. + // The minimum is just a little larger than the size of the button itself. + // The maximum is an arbitrary number that should be smaller than most + // screens. + static const CGFloat kMinWidth; + static const CGFloat kMinHeight; + static const CGFloat kMaxWidth; + static const CGFloat kMaxHeight; + private: RenderViewHost* render_view_host() const; diff --git a/chrome/browser/cocoa/extension_view_mac.mm b/chrome/browser/cocoa/extension_view_mac.mm index 0ff029a..ca00978 100644 --- a/chrome/browser/cocoa/extension_view_mac.mm +++ b/chrome/browser/cocoa/extension_view_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,12 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" +// The minimum/maximum dimensions of the popup. +const CGFloat ExtensionViewMac::kMinWidth = 25.0; +const CGFloat ExtensionViewMac::kMinHeight = 25.0; +const CGFloat ExtensionViewMac::kMaxWidth = 800.0; +const CGFloat ExtensionViewMac::kMaxHeight = 600.0; + ExtensionViewMac::ExtensionViewMac(ExtensionHost* extension_host, Browser* browser) : is_toolstrip_(true), @@ -69,6 +75,14 @@ void ExtensionViewMac::UpdatePreferredSize(const gfx::Size& new_size) { } void ExtensionViewMac::RenderViewCreated() { + // Do not allow webkit to draw scroll bars on views smaller than + // the largest size view allowed. The view will be resized to make + // scroll bars unnecessary. Scroll bars change the height of the + // view, so not drawing them is necessary to avoid infinite resizing. + gfx::Size largest_popup_size( + CGSizeMake(ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight)); + extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size); + if (!pending_background_.empty() && render_view_host()->view()) { render_widget_host_view_->SetBackground(pending_background_); pending_background_.reset(); diff --git a/chrome/browser/cocoa/extensions/extension_popup_controller.mm b/chrome/browser/cocoa/extensions/extension_popup_controller.mm index 4606a92..72271b5 100644 --- a/chrome/browser/cocoa/extensions/extension_popup_controller.mm +++ b/chrome/browser/cocoa/extensions/extension_popup_controller.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,21 +15,19 @@ #include "chrome/browser/profile.h" #include "chrome/common/notification_service.h" -// The minimum/maximum dimensions of the popup. -// The minimum is just a little larger than the size of the button itself. -// The maximum is an arbitrary number that should be smaller than most screens. namespace { -const CGFloat kMinWidth = 25; -const CGFloat kMinHeight = 25; -const CGFloat kMaxWidth = 800; -const CGFloat kMaxHeight = 600; - // The duration for any animations that might be invoked by this controller. const NSTimeInterval kAnimationDuration = 0.2; // There should only be one extension popup showing at one time. Keep a // reference to it here. static ExtensionPopupController* gPopup; + +// Given a value and a rage, clamp the value into the range. +CGFloat Clamp(CGFloat value, CGFloat min, CGFloat max) { + return std::max(min, std::min(max, value)); +} + } // namespace @interface ExtensionPopupController(Private) @@ -179,8 +177,12 @@ static ExtensionPopupController* gPopup; extensionFrame_ = [extensionView_ frame]; // Constrain the size of the view. [extensionView_ setFrameSize:NSMakeSize( - std::max(kMinWidth, std::min(kMaxWidth, NSWidth(extensionFrame_))), - std::max(kMinHeight, std::min(kMaxHeight, NSHeight(extensionFrame_))))]; + Clamp(NSWidth(extensionFrame_), + ExtensionViewMac::kMinWidth, + ExtensionViewMac::kMaxWidth), + Clamp(NSHeight(extensionFrame_), + ExtensionViewMac::kMinHeight, + ExtensionViewMac::kMaxHeight))]; // Pad the window by half of the rounded corner radius to prevent the // extension's view from bleeding out over the corners. @@ -238,13 +240,13 @@ static ExtensionPopupController* gPopup; // Private (TestingAPI) + (NSSize)minPopupSize { - NSSize minSize = {kMinWidth, kMinHeight}; + NSSize minSize = {ExtensionViewMac::kMinWidth, ExtensionViewMac::kMinHeight}; return minSize; } // Private (TestingAPI) + (NSSize)maxPopupSize { - NSSize maxSize = {kMaxWidth, kMaxHeight}; + NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; return maxSize; } diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 78d83da..e139899 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -356,6 +356,12 @@ void ExtensionHost::InsertThemeCSS() { render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripThemeCSS"); } +void ExtensionHost::DisableScrollbarsForSmallWindows( + const gfx::Size& size_limit) { + render_view_host()->Send(new ViewMsg_DisableScrollbarsForSmallWindows( + render_view_host()->routing_id(), size_limit)); +} + void ExtensionHost::DidStopLoading() { bool notify = !did_stop_loading_; did_stop_loading_ = true; diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index c5ea9b2..fd155d7 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -100,6 +100,10 @@ class ExtensionHost : public ExtensionPopupHost::PopupDelegate, // Insert the theme CSS for a toolstrip/mole. void InsertThemeCSS(); + // Tell the renderer not to draw scrollbars on windows smaller than + // |size_limit| in both width and height. + void DisableScrollbarsForSmallWindows(const gfx::Size& size_limit); + // RenderViewHostDelegate implementation. virtual RenderViewHostDelegate::View* GetViewDelegate(); virtual const GURL& GetURL() const { return url_; } diff --git a/chrome/browser/gtk/extension_view_gtk.cc b/chrome/browser/gtk/extension_view_gtk.cc index 36cb94c..cb03bc9 100644 --- a/chrome/browser/gtk/extension_view_gtk.cc +++ b/chrome/browser/gtk/extension_view_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -64,4 +64,10 @@ void ExtensionViewGtk::RenderViewCreated() { render_widget_host_view_->SetBackground(pending_background_); pending_background_.reset(); } + + // Tell the renderer not to draw scrollbars in popups unless the + // popups are at the maximum allowed size. + gfx::Size largest_popup_size(ExtensionViewGtk::kMaxWidth, + ExtensionViewGtk::kMaxHeight); + extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size); } diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index d9cee06..608716c 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -750,6 +750,11 @@ IPC_BEGIN_MESSAGES(View) // Used to instruct the RenderView to send back updates to the preferred size. IPC_MESSAGE_ROUTED0(ViewMsg_EnablePreferredSizeChangedMode) + // Used to tell the renderer not to add scrollbars with height and + // width below a threshold. + IPC_MESSAGE_ROUTED1(ViewMsg_DisableScrollbarsForSmallWindows, + gfx::Size /* disable_scrollbar_size_limit */) + // Used to inform the renderer that the browser has displayed its // requested notification. IPC_MESSAGE_ROUTED1(ViewMsg_PostDisplayToNotificationObject, diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index a35f97b..03c0850 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -585,6 +585,8 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, OnEnablePreferredSizeChangedMode) + IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, + OnDisableScrollbarsForSmallWindows) IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, OnUpdateBrowserWindowId) @@ -3628,6 +3630,11 @@ void RenderView::OnEnablePreferredSizeChangedMode() { } } +void RenderView::OnDisableScrollbarsForSmallWindows( + const gfx::Size& disable_scrollbar_size_limit) { + disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; +} + void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { renderer_preferences_ = renderer_prefs; UpdateFontRenderingFromRendererPrefs(); @@ -3922,8 +3929,20 @@ void RenderView::OnMoveOrResizeStarted() { void RenderView::OnResize(const gfx::Size& new_size, const gfx::Rect& resizer_rect) { - if (webview()) + if (webview()) { webview()->hideSuggestionsPopup(); + + if (send_preferred_size_changes_) { + // If resizing to a size larger than |disable_scrollbars_size_limit_| in + // either width or height, allow scroll bars. + bool allow_scrollbars = ( + disable_scrollbars_size_limit_.width() <= new_size.width() || + disable_scrollbars_size_limit_.height() <= new_size.height() + ); + webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars); + } + } + RenderWidget::OnResize(new_size, resizer_rect); } @@ -4555,4 +4574,3 @@ WebKit::WebGeolocationServiceInterface* RenderView::getGeolocationService() { geolocation_dispatcher_.reset(new GeolocationDispatcher(this)); return geolocation_dispatcher_.get(); } - diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 34069e9..797402f 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -677,6 +677,8 @@ class RenderView : public RenderWidget, void OnFileChooserResponse(const std::vector<FilePath>& file_names); void OnEnableViewSourceMode(); void OnEnablePreferredSizeChangedMode(); + void OnDisableScrollbarsForSmallWindows( + const gfx::Size& disable_scrollbars_size_limit); void OnSetRendererPrefs(const RendererPreferences& renderer_prefs); void OnMediaPlayerActionAt(const gfx::Point& location, const WebKit::WebMediaPlayerAction& action); @@ -1053,6 +1055,17 @@ class RenderView : public RenderWidget, // https://bugs.webkit.org/show_bug.cgi?id=32807. base::RepeatingTimer<RenderView> preferred_size_change_timer_; + // If non-empty, and |send_preferred_size_changes_| is true, disable drawing + // scroll bars on windows smaller than this size. Used for windows that the + // browser resizes to the size of the content, such as browser action popups. + // If a render view is set to the minimum size of its content, webkit may add + // scroll bars. This makes sense for fixed sized windows, but it does not + // make sense when the size of the view was chosen to fit the content. + // This setting ensures that no scroll bars are drawn. The size limit exists + // because if the view grows beyond a size known to the browser, scroll bars + // should be drawn. + gfx::Size disable_scrollbars_size_limit_; + // The text selection the last time DidChangeSelection got called. std::string last_selection_; |