Chromium Code Reviews| Index: content/renderer/render_view.cc |
| diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc |
| index 1b63862e5ae515a31fab6b863ac63b33d81709d1..d58749a3c0df18762a3d8730b383dc03269cde5a 100644 |
| --- a/content/renderer/render_view.cc |
| +++ b/content/renderer/render_view.cc |
| @@ -262,6 +262,10 @@ static const int kDelaySecondsForContentStateSync = 1; |
| // The maximum number of popups that can be spawned from one page. |
| static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| +// The default layout width and height for pages when fixed layout is enabled. |
| +static const int kDefaultLayoutWidth = 980; |
| +static const int kDefaultLayoutHeight = 640; |
| + |
| static const float kScalingIncrement = 0.1f; |
| static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| @@ -367,6 +371,9 @@ RenderView::RenderView(RenderThreadBase* render_thread, |
| accessibility_ack_pending_(false), |
| p2p_socket_dispatcher_(NULL), |
| devtools_agent_(NULL), |
| + user_scalable_(true), |
| + minimum_scale_(content::kMinPageScaleFactor), |
| + maximum_scale_(content::kMaxPageScaleFactor), |
| session_storage_namespace_id_(session_storage_namespace_id), |
| handling_select_range_(false) { |
| routing_id_ = routing_id; |
| @@ -1226,6 +1233,17 @@ void RenderView::UpdateURL(WebFrame* frame) { |
| accessibility_.reset(); |
| pending_accessibility_notifications_.clear(); |
| } |
| + const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| + if (cmd_line->HasSwitch(switches::kEnableFixedLayout)) { |
| + // Only enable fixed layout for normal web content. |
| + GURL frame_url = GURL(request.url()); |
| + if (frame_url.SchemeIs(chrome::kHttpScheme) || |
| + frame_url.SchemeIs(chrome::kHttpsScheme)) { |
|
jamesr
2011/09/02 17:43:09
I really doubt this is the best way to test for we
Fady Samuel
2011/09/08 23:46:39
This is intentional. WebUI is broken with fixed la
jamesr
2011/09/09 00:11:40
Good grief! That is horrible. What is wrong with
|
| + webview()->enableFixedLayoutMode(true); |
| + webview()->setFixedLayoutSize( |
| + WebSize(kDefaultLayoutWidth, kDefaultLayoutHeight)); |
| + } |
| + } |
| } |
| // Tell the embedding application that the title of the active page has changed |
| @@ -1438,6 +1456,10 @@ WebExternalPopupMenu* RenderView::createExternalPopupMenu( |
| return external_popup_menu_.get(); |
| } |
| +WebRect RenderView::getDeviceRect() const { |
| + return WebRect(0, 0, size().width(), size().height()); |
| +} |
| + |
| RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer( |
| webkit::ppapi::PluginInstance* plugin) { |
| GURL active_url; |
| @@ -2512,6 +2534,10 @@ void RenderView::didCommitProvisionalLoad(WebFrame* frame, |
| history_list_length_ = history_list_offset_ + 1; |
| history_page_ids_.resize(history_list_length_, -1); |
| history_page_ids_[history_list_offset_] = page_id_; |
| + |
| + // Prepare for initialization to overview when content size becomes |
| + // available. |
| + page_scale_factor_set_ = false; |
| } else { |
| // Inspect the navigation_state on this frame to see if the navigation |
| // corresponds to a session history navigation... Note: |frame| may or |
| @@ -2833,6 +2859,9 @@ void RenderView::didCreateIsolatedScriptContext( |
| } |
| void RenderView::didUpdateLayout(WebFrame* frame) { |
| + if (webview() && webview()->isFixedLayoutModeEnabled() && |
| + webview()->mainFrame() == frame) |
| + TryInitializeScale(); |
| // We don't always want to set up a timer, only if we've been put in that |
| // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
| // message. |
| @@ -2869,9 +2898,42 @@ void RenderView::CheckPreferredSize() { |
| preferred_size_)); |
| } |
| +gfx::Point RenderView::ClampOffsetAtScale(const gfx::Point& offset, |
| + float scale) { |
| + gfx::Point pt = offset; |
| + float delta_scale = scale / GetPageScaleFactor(); |
| + int doc_width = GetContentSize().width() * delta_scale; |
| + int doc_height = GetContentSize().height() * delta_scale; |
| + pt.set_x(std::min(doc_width - size_.width(), pt.x())); |
| + pt.set_y(std::min(doc_height - size_.height(), pt.y())); |
| + pt.set_x(std::max(0, pt.x())); |
| + pt.set_y(std::max(0, pt.y())); |
| + return pt; |
| +} |
| + |
| +float RenderView::ComputeOverviewScale(gfx::Size content_size) { |
| + if (content_size.IsEmpty() || size_.IsEmpty()) |
| + return 0.0f; |
| + return ComputeScaleWithinLimits(0.0f); |
| +} |
| + |
| +float RenderView::ComputeScaleWithinLimits(float scale) { |
| + // TODO(fsamuel): Need to take into account dpi scale. |
| + float min_scale = minimum_scale_; |
| + float max_scale = maximum_scale_; |
| + |
| + gfx::Size content_size = GetContentSize(); |
| + if (!content_size.IsEmpty() && !size_.IsEmpty()) { |
| + min_scale = std::max(min_scale, (float) size_.width() / |
| + (content_size.width() / GetPageScaleFactor())); |
| + } |
| + return std::min(std::max(scale, min_scale), max_scale); |
| +} |
| + |
| void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) { |
| if (webview()->mainFrame() != frame) |
| return; |
| + |
| WebView* frameView = frame->view(); |
| if (!frameView) |
| return; |
| @@ -3117,6 +3179,25 @@ void RenderView::SyncSelectionIfRequired() { |
| start, end)); |
| } |
| +bool RenderView::TryInitializeScale() { |
| + // Make the page to fit the new size of the window if it wasn't set by |
| + // the page or user yet. |
| + if (page_scale_factor_set_) |
| + return false; |
| + float overview_scale = ComputeOverviewScale(GetContentSize()); |
| + if (overview_scale == 0.0f) |
| + return false; |
| + SetPageScaleFactor(overview_scale); |
| + return true; |
| +} |
| + |
| +void RenderView::UpdatePageScale(gfx::Size new_content_size) { |
| + float overview_scale = ComputeOverviewScale(new_content_size); |
| + if (overview_scale == 0.0f) |
| + return; |
| + SetPageScaleFactor(overview_scale); |
| +} |
| + |
| GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, |
| ErrorPageType error_type) { |
| @@ -3928,6 +4009,37 @@ bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| return true; |
| } |
| +void RenderView::SetPageScaleFactor(float scale) { |
| + scale = ComputeScaleWithinLimits(scale); |
| + SetPageScaleFactorAndScroll(scale, |
| + gfx::Point(GetScrollOffset().x() / GetPageScaleFactor() * scale, |
| + GetScrollOffset().y() / GetPageScaleFactor() * scale)); |
| +} |
| + |
| +void RenderView::SetPageScaleFactorAndScroll(float scale, |
| + const gfx::Point& offset) { |
| + scale = ComputeScaleWithinLimits(scale); |
| + gfx::Point pt = ClampOffsetAtScale(offset, scale); |
| + |
| + if (scale != GetPageScaleFactor() || pt.x() != GetScrollOffset().x() || |
| + pt.y() != GetScrollOffset().y()) { |
| + webview()->scalePage(scale, WebPoint(pt.x(), pt.y())); |
| + } |
| + page_scale_factor_set_ = true; |
| +} |
| + |
| +void RenderView::SetPageScaleFactorWithAnchor(float scale, |
| + const gfx::Point& window_anchor) { |
| + scale = ComputeScaleWithinLimits(scale); |
| + gfx::Point old_offset = GetScrollOffset(); |
| + float old_scale = GetPageScaleFactor(); |
| + int anchor_x = window_anchor.x(); |
| + int anchor_y = window_anchor.y(); |
| + SetPageScaleFactorAndScroll(scale, |
| + gfx::Point((anchor_x + old_offset.x()) * scale / old_scale - anchor_x, |
| + (anchor_y + old_offset.y()) * scale / old_scale - anchor_y)); |
| +} |
| + |
| void RenderView::AltErrorPageFinished(WebFrame* frame, |
| const WebURLError& original_error, |
| const std::string& html) { |
| @@ -3945,6 +4057,7 @@ void RenderView::OnMoveOrResizeStarted() { |
| void RenderView::OnResize(const gfx::Size& new_size, |
| const gfx::Rect& resizer_rect) { |
| if (webview()) { |
| + |
|
jam
2011/09/02 17:11:41
?
|
| webview()->hidePopups(); |
| if (send_preferred_size_changes_) { |
| webview()->mainFrame()->setCanHaveScrollbars( |
| @@ -3954,6 +4067,13 @@ void RenderView::OnResize(const gfx::Size& new_size, |
| } |
| RenderWidget::OnResize(new_size, resizer_rect); |
| + if (webview()) { |
| + // TODO(fsamuel): Need to detect case where the user set pageScaleFactor |
| + // and adjust it appropriately on resize. |
| + if (webview()->isFixedLayoutModeEnabled()) { |
| + UpdatePageScale(new_size); |
| + } |
| + } |
| } |
| void RenderView::DidInitiatePaint() { |
| @@ -4015,6 +4135,17 @@ webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint( |
| paint_bounds, dib, location, clip); |
| } |
| +gfx::Size RenderView::GetContentSize() { |
| + WebKit::WebSize size = webview()->mainFrame()->contentsSize(); |
| + return gfx::Size(size.width, size.height); |
| +} |
| + |
| +float RenderView::GetPageScaleFactor() { |
| + if (!webview()) |
| + return 1.0f; |
| + return webview()->pageScaleFactor(); |
| +} |
| + |
| gfx::Point RenderView::GetScrollOffset() { |
| WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
| return gfx::Point(scroll_offset.width, scroll_offset.height); |