Commit 244ac189 authored by levin@chromium.org's avatar levin@chromium.org

Add autoresize capability to chromium.

Review URL: http://codereview.chromium.org/8704005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112719 0039d316-1c4b-4281-b951-d872f2087c98
parent 4f21d0f8
...@@ -1023,6 +1023,10 @@ void RenderViewHost::OnMsgDidContentsPreferredSizeChange( ...@@ -1023,6 +1023,10 @@ void RenderViewHost::OnMsgDidContentsPreferredSizeChange(
delegate_->UpdatePreferredSize(new_size); delegate_->UpdatePreferredSize(new_size);
} }
void RenderViewHost::OnRenderAutoResized(const gfx::Size& new_size) {
delegate_->UpdatePreferredSize(new_size);
}
void RenderViewHost::OnMsgDidChangeScrollbarsForMainFrame( void RenderViewHost::OnMsgDidChangeScrollbarsForMainFrame(
bool has_horizontal_scrollbar, bool has_vertical_scrollbar) { bool has_horizontal_scrollbar, bool has_vertical_scrollbar) {
if (view()) if (view())
...@@ -1339,6 +1343,12 @@ void RenderViewHost::EnablePreferredSizeMode() { ...@@ -1339,6 +1343,12 @@ void RenderViewHost::EnablePreferredSizeMode() {
Send(new ViewMsg_EnablePreferredSizeChangedMode(routing_id())); Send(new ViewMsg_EnablePreferredSizeChangedMode(routing_id()));
} }
void RenderViewHost::EnableAutoResize(const gfx::Size& min_size,
const gfx::Size& max_size) {
SetShouldAutoResize(true);
Send(new ViewMsg_EnableAutoResize(routing_id(), min_size, max_size));
}
void RenderViewHost::ExecuteCustomContextMenuCommand( void RenderViewHost::ExecuteCustomContextMenuCommand(
int action, const webkit_glue::CustomContextMenuContext& context) { int action, const webkit_glue::CustomContextMenuContext& context) {
Send(new ViewMsg_CustomContextMenuAction(routing_id(), context, action)); Send(new ViewMsg_CustomContextMenuAction(routing_id(), context, action));
......
...@@ -442,6 +442,10 @@ class CONTENT_EXPORT RenderViewHost : public RenderWidgetHost { ...@@ -442,6 +442,10 @@ class CONTENT_EXPORT RenderViewHost : public RenderWidgetHost {
// Instructs the RenderView to send back updates to the preferred size. // Instructs the RenderView to send back updates to the preferred size.
void EnablePreferredSizeMode(); void EnablePreferredSizeMode();
// Instructs the RenderView to automatically resize and send back updates
// for the new size.
void EnableAutoResize(const gfx::Size& min_size, const gfx::Size& max_size);
// Executes custom context menu action that was provided from WebKit. // Executes custom context menu action that was provided from WebKit.
void ExecuteCustomContextMenuCommand( void ExecuteCustomContextMenuCommand(
int action, const webkit_glue::CustomContextMenuContext& context); int action, const webkit_glue::CustomContextMenuContext& context);
...@@ -495,6 +499,7 @@ class CONTENT_EXPORT RenderViewHost : public RenderWidgetHost { ...@@ -495,6 +499,7 @@ class CONTENT_EXPORT RenderViewHost : public RenderWidgetHost {
virtual void OnUserGesture() OVERRIDE; virtual void OnUserGesture() OVERRIDE;
virtual void NotifyRendererUnresponsive() OVERRIDE; virtual void NotifyRendererUnresponsive() OVERRIDE;
virtual void NotifyRendererResponsive() OVERRIDE; virtual void NotifyRendererResponsive() OVERRIDE;
virtual void OnRenderAutoResized(const gfx::Size& size) OVERRIDE;
virtual void RequestToLockMouse() OVERRIDE; virtual void RequestToLockMouse() OVERRIDE;
virtual bool IsFullscreen() const OVERRIDE; virtual bool IsFullscreen() const OVERRIDE;
virtual void OnMsgFocus() OVERRIDE; virtual void OnMsgFocus() OVERRIDE;
......
...@@ -89,6 +89,7 @@ RenderWidgetHost::RenderWidgetHost(content::RenderProcessHost* process, ...@@ -89,6 +89,7 @@ RenderWidgetHost::RenderWidgetHost(content::RenderProcessHost* process,
is_accelerated_compositing_active_(false), is_accelerated_compositing_active_(false),
repaint_ack_pending_(false), repaint_ack_pending_(false),
resize_ack_pending_(false), resize_ack_pending_(false),
should_auto_resize_(false),
mouse_move_pending_(false), mouse_move_pending_(false),
mouse_wheel_pending_(false), mouse_wheel_pending_(false),
touch_move_pending_(false), touch_move_pending_(false),
...@@ -332,7 +333,7 @@ void RenderWidgetHost::WasRestored() { ...@@ -332,7 +333,7 @@ void RenderWidgetHost::WasRestored() {
void RenderWidgetHost::WasResized() { void RenderWidgetHost::WasResized() {
if (resize_ack_pending_ || !process_->HasConnection() || !view_ || if (resize_ack_pending_ || !process_->HasConnection() || !view_ ||
!renderer_initialized_) { !renderer_initialized_ || should_auto_resize_) {
return; return;
} }
...@@ -868,6 +869,20 @@ bool RenderWidgetHost::IsFullscreen() const { ...@@ -868,6 +869,20 @@ bool RenderWidgetHost::IsFullscreen() const {
return false; return false;
} }
void RenderWidgetHost::SetShouldAutoResize(bool enable) {
// Note if this switches from true to false then one has to verify that the
// mechanics about all the messaging works. For example, what happens to a
// update message rect that was in progress from the render widget. Perhaps,
// on a transition to false, this should do a WasResized, but what if that
// will not trigger a resize message...etc. Due to these complications it is
// fitting that this method doesn't look like a simple set method.
DCHECK(enable);
// TODO: Change this to enable instead of true when this supports turning
// off auto-resize.
should_auto_resize_ = true;
}
void RenderWidgetHost::Destroy() { void RenderWidgetHost::Destroy() {
content::NotificationService::current()->Notify( content::NotificationService::current()->Notify(
content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
...@@ -991,11 +1006,13 @@ void RenderWidgetHost::OnMsgUpdateRect( ...@@ -991,11 +1006,13 @@ void RenderWidgetHost::OnMsgUpdateRect(
// resize_ack_pending_ needs to be cleared before we call DidPaintRect, since // resize_ack_pending_ needs to be cleared before we call DidPaintRect, since
// that will end up reaching GetBackingStore. // that will end up reaching GetBackingStore.
if (is_resize_ack) { if (is_resize_ack || should_auto_resize_) {
DCHECK(resize_ack_pending_); if (is_resize_ack) {
resize_ack_pending_ = false; DCHECK(resize_ack_pending_);
in_flight_size_.SetSize(0, 0); resize_ack_pending_ = false;
in_flight_reserved_rect_.SetRect(0, 0, 0, 0); in_flight_size_.SetSize(0, 0);
in_flight_reserved_rect_.SetRect(0, 0, 0, 0);
}
// Update our knowledge of the RenderWidget's resizer rect. // Update our knowledge of the RenderWidget's resizer rect.
// ViewMsg_Resize is acknowledged only when view size is actually changed, // ViewMsg_Resize is acknowledged only when view size is actually changed,
// otherwise current_reserved_rect_ is updated immediately after sending // otherwise current_reserved_rect_ is updated immediately after sending
...@@ -1056,6 +1073,10 @@ void RenderWidgetHost::OnMsgUpdateRect( ...@@ -1056,6 +1073,10 @@ void RenderWidgetHost::OnMsgUpdateRect(
DidUpdateBackingStore(params, paint_start); DidUpdateBackingStore(params, paint_start);
} }
if (should_auto_resize_) {
OnRenderAutoResized(params.view_size);
}
// Log the time delta for processing a paint message. On platforms that don't // Log the time delta for processing a paint message. On platforms that don't
// support asynchronous painting, this is equivalent to // support asynchronous painting, this is equivalent to
// MPArch.RWH_TotalPaintTime. // MPArch.RWH_TotalPaintTime.
......
...@@ -496,6 +496,9 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener, ...@@ -496,6 +496,9 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener,
virtual void NotifyRendererUnresponsive() {} virtual void NotifyRendererUnresponsive() {}
virtual void NotifyRendererResponsive() {} virtual void NotifyRendererResponsive() {}
// Called when auto-resize resulted in the renderer size changing.
virtual void OnRenderAutoResized(const gfx::Size& new_size) {}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// RenderViewHost overrides this method to impose further restrictions on when // RenderViewHost overrides this method to impose further restrictions on when
...@@ -510,6 +513,10 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener, ...@@ -510,6 +513,10 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener,
// RenderViewHost overrides this method to report when in fullscreen mode. // RenderViewHost overrides this method to report when in fullscreen mode.
virtual bool IsFullscreen() const; virtual bool IsFullscreen() const;
// Indicates if the render widget host should track the render widget's size
// as opposed to visa versa.
void SetShouldAutoResize(bool enable);
protected: protected:
// true if a renderer has once been valid. We use this flag to display a sad // true if a renderer has once been valid. We use this flag to display a sad
// tab only when we lose our renderer and not if a paint occurs during // tab only when we lose our renderer and not if a paint occurs during
...@@ -674,6 +681,10 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener, ...@@ -674,6 +681,10 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Channel::Listener,
// hand is updated when the resize message is sent. // hand is updated when the resize message is sent.
gfx::Rect in_flight_reserved_rect_; gfx::Rect in_flight_reserved_rect_;
// True if the render widget host should track the render widget's size as
// opposed to visa versa.
bool should_auto_resize_;
// True if a mouse move event was sent to the render view and we are waiting // True if a mouse move event was sent to the render view and we are waiting
// for a corresponding ViewHostMsg_HandleInputEvent_ACK message. // for a corresponding ViewHostMsg_HandleInputEvent_ACK message.
bool mouse_move_pending_; bool mouse_move_pending_;
......
...@@ -1024,6 +1024,12 @@ IPC_MESSAGE_ROUTED0(ViewMsg_Move_ACK) ...@@ -1024,6 +1024,12 @@ IPC_MESSAGE_ROUTED0(ViewMsg_Move_ACK)
// Used to instruct the RenderView to send back updates to the preferred size. // Used to instruct the RenderView to send back updates to the preferred size.
IPC_MESSAGE_ROUTED0(ViewMsg_EnablePreferredSizeChangedMode) IPC_MESSAGE_ROUTED0(ViewMsg_EnablePreferredSizeChangedMode)
// Used to instruct the RenderView to automatically resize and send back
// updates for the new size.
IPC_MESSAGE_ROUTED2(ViewMsg_EnableAutoResize,
gfx::Size /* min_size */,
gfx::Size /* max_size */)
// Changes the text direction of the currently selected input field (if any). // Changes the text direction of the currently selected input field (if any).
IPC_MESSAGE_ROUTED1(ViewMsg_SetTextDirection, IPC_MESSAGE_ROUTED1(ViewMsg_SetTextDirection,
WebKit::WebTextDirection /* direction */) WebKit::WebTextDirection /* direction */)
......
...@@ -681,6 +681,7 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) { ...@@ -681,6 +681,7 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
OnEnablePreferredSizeChangedMode) OnEnablePreferredSizeChangedMode)
IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
OnDisableScrollbarsForSmallWindows) OnDisableScrollbarsForSmallWindows)
IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
...@@ -3906,6 +3907,14 @@ void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) { ...@@ -3906,6 +3907,14 @@ void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
} }
} }
void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
const gfx::Size& max_size) {
DCHECK(disable_scrollbars_size_limit_.IsEmpty());
if (!webview())
return;
webview()->enableAutoResizeMode(true, min_size, max_size);
}
void RenderViewImpl::OnEnablePreferredSizeChangedMode() { void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
if (send_preferred_size_changes_) if (send_preferred_size_changes_)
return; return;
......
...@@ -822,6 +822,7 @@ class RenderViewImpl : public RenderWidget, ...@@ -822,6 +822,7 @@ class RenderViewImpl : public RenderWidget,
const gfx::Point& screen_pt, const gfx::Point& screen_pt,
WebKit::WebDragOperationsMask operations_allowed); WebKit::WebDragOperationsMask operations_allowed);
void OnEnablePreferredSizeChangedMode(); void OnEnablePreferredSizeChangedMode();
void OnEnableAutoResize(const gfx::Size& min_size, const gfx::Size& max_size);
void OnEnumerateDirectoryResponse(int id, const std::vector<FilePath>& paths); void OnEnumerateDirectoryResponse(int id, const std::vector<FilePath>& paths);
void OnExecuteEditCommand(const std::string& name, const std::string& value); void OnExecuteEditCommand(const std::string& name, const std::string& value);
void OnFileChooserResponse(const std::vector<FilePath>& paths); void OnFileChooserResponse(const std::vector<FilePath>& paths);
......
...@@ -924,6 +924,10 @@ void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { ...@@ -924,6 +924,10 @@ void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
} }
void RenderWidget::didAutoResize(const WebSize& new_size) {
size_ = new_size;
}
void RenderWidget::didActivateCompositor(int compositor_identifier) { void RenderWidget::didActivateCompositor(int compositor_identifier) {
TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor"); TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
......
...@@ -104,6 +104,7 @@ class CONTENT_EXPORT RenderWidget ...@@ -104,6 +104,7 @@ class CONTENT_EXPORT RenderWidget
// WebKit::WebWidgetClient // WebKit::WebWidgetClient
virtual void didInvalidateRect(const WebKit::WebRect&); virtual void didInvalidateRect(const WebKit::WebRect&);
virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect); virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect);
virtual void didAutoResize(const WebKit::WebSize& new_size);
virtual void didActivateCompositor(int compositorIdentifier); virtual void didActivateCompositor(int compositorIdentifier);
virtual void didDeactivateCompositor(); virtual void didDeactivateCompositor();
virtual void didCommitAndDrawCompositorFrame(); virtual void didCommitAndDrawCompositorFrame();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment