| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 // Cache the size when RenderViewHost is first created. | 272 // Cache the size when RenderViewHost is first created. |
| 273 virtual void RenderViewCreated( | 273 virtual void RenderViewCreated( |
| 274 content::RenderViewHost* render_view_host) OVERRIDE { | 274 content::RenderViewHost* render_view_host) OVERRIDE { |
| 275 render_view_sizes_[render_view_host].rwhv_create_size = | 275 render_view_sizes_[render_view_host].rwhv_create_size = |
| 276 render_view_host->GetView()->GetViewBounds().size(); | 276 render_view_host->GetView()->GetViewBounds().size(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 // Enlarge WebContentsView by |wcv_resize_insets_| while the navigation entry | 279 // Enlarge WebContentsView by |wcv_resize_insets_| while the navigation entry |
| 280 // is pending. | 280 // is pending. |
| 281 virtual void NavigateToPendingEntry( | 281 virtual void DidCreatePendingEntry( |
| 282 const GURL& url, | 282 const GURL& url, |
| 283 NavigationController::ReloadType reload_type) OVERRIDE { | 283 NavigationController::ReloadType reload_type) OVERRIDE { |
| 284 if (wcv_resize_insets_.IsEmpty()) | 284 if (wcv_resize_insets_.IsEmpty()) |
| 285 return; | 285 return; |
| 286 // Resizing the main browser window by |wcv_resize_insets_| will | 286 // Resizing the main browser window by |wcv_resize_insets_| will |
| 287 // automatically resize the WebContentsView by the same amount. | 287 // automatically resize the WebContentsView by the same amount. |
| 288 // Just resizing WebContentsView directly doesn't work on Linux, because the | 288 // Just resizing WebContentsView directly doesn't work on Linux, because the |
| 289 // next automatic layout of the browser window will resize WebContentsView | 289 // next automatic layout of the browser window will resize WebContentsView |
| 290 // back to the previous size. To make it consistent, resize main browser | 290 // back to the previous size. To make it consistent, resize main browser |
| 291 // window on all platforms. | 291 // window on all platforms. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 312 | 312 |
| 313 private: | 313 private: |
| 314 struct Sizes { | 314 struct Sizes { |
| 315 gfx::Size rwhv_create_size; // Size of RenderWidgetHostView when created. | 315 gfx::Size rwhv_create_size; // Size of RenderWidgetHostView when created. |
| 316 gfx::Size rwhv_commit_size; // Size of RenderWidgetHostView when committed. | 316 gfx::Size rwhv_commit_size; // Size of RenderWidgetHostView when committed. |
| 317 gfx::Size wcv_commit_size; // Size of WebContentsView when committed. | 317 gfx::Size wcv_commit_size; // Size of WebContentsView when committed. |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 typedef std::map<content::RenderViewHost*, Sizes> RenderViewSizes; | 320 typedef std::map<content::RenderViewHost*, Sizes> RenderViewSizes; |
| 321 RenderViewSizes render_view_sizes_; | 321 RenderViewSizes render_view_sizes_; |
| 322 // Enlarge WebContentsView by this size insets in NavigateToPendingEntry. | 322 // Enlarge WebContentsView by this size insets in DidCreatePendingEntry. |
| 323 gfx::Size wcv_resize_insets_; | 323 gfx::Size wcv_resize_insets_; |
| 324 BrowserWindow* browser_window_; // Weak ptr. | 324 BrowserWindow* browser_window_; // Weak ptr. |
| 325 | 325 |
| 326 DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); | 326 DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 } // namespace | 329 } // namespace |
| 330 | 330 |
| 331 class BrowserTest : public ExtensionBrowserTest { | 331 class BrowserTest : public ExtensionBrowserTest { |
| 332 protected: | 332 protected: |
| (...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2537 gfx::Size rwhv_create_size2, rwhv_commit_size2, wcv_commit_size2; | 2537 gfx::Size rwhv_create_size2, rwhv_commit_size2, wcv_commit_size2; |
| 2538 observer.GetSizeForRenderViewHost(web_contents->GetRenderViewHost(), | 2538 observer.GetSizeForRenderViewHost(web_contents->GetRenderViewHost(), |
| 2539 &rwhv_create_size2, | 2539 &rwhv_create_size2, |
| 2540 &rwhv_commit_size2, | 2540 &rwhv_commit_size2, |
| 2541 &wcv_commit_size2); | 2541 &wcv_commit_size2); |
| 2542 // The create height of RenderWidgetHostView should include the height inset. | 2542 // The create height of RenderWidgetHostView should include the height inset. |
| 2543 EXPECT_EQ(gfx::Size(initial_wcv_size.width(), | 2543 EXPECT_EQ(gfx::Size(initial_wcv_size.width(), |
| 2544 initial_wcv_size.height() + height_inset), | 2544 initial_wcv_size.height() + height_inset), |
| 2545 rwhv_create_size2); | 2545 rwhv_create_size2); |
| 2546 // WebContentsView was resized in | 2546 // WebContentsView was resized in |
| 2547 // RenderViewSizeObserver::NavigateToPendingEntry after RenderWidgetHostView | 2547 // RenderViewSizeObserver::DidCreatePendingEntry after RenderWidgetHostView |
| 2548 // was created, so the commit size should be resized accordingly. | 2548 // was created, so the commit size should be resized accordingly. |
| 2549 gfx::Size exp_commit_size(initial_wcv_size); | 2549 gfx::Size exp_commit_size(initial_wcv_size); |
| 2550 exp_commit_size.Enlarge(wcv_resize_insets.width(), | 2550 exp_commit_size.Enlarge(wcv_resize_insets.width(), |
| 2551 wcv_resize_insets.height() + height_inset); | 2551 wcv_resize_insets.height() + height_inset); |
| 2552 EXPECT_EQ(exp_commit_size, rwhv_commit_size2); | 2552 EXPECT_EQ(exp_commit_size, rwhv_commit_size2); |
| 2553 EXPECT_EQ(exp_commit_size, wcv_commit_size2); | 2553 EXPECT_EQ(exp_commit_size, wcv_commit_size2); |
| 2554 // Sizes of RenderWidgetHostView and WebContentsView before and after | 2554 // Sizes of RenderWidgetHostView and WebContentsView before and after |
| 2555 // WebContentsDelegate::DidNavigateMainFramePostCommit should be the same. | 2555 // WebContentsDelegate::DidNavigateMainFramePostCommit should be the same. |
| 2556 EXPECT_EQ(rwhv_commit_size2, | 2556 EXPECT_EQ(rwhv_commit_size2, |
| 2557 web_contents->GetRenderWidgetHostView()->GetViewBounds().size()); | 2557 web_contents->GetRenderWidgetHostView()->GetViewBounds().size()); |
| 2558 EXPECT_EQ(wcv_commit_size2, web_contents->GetView()->GetContainerSize()); | 2558 EXPECT_EQ(wcv_commit_size2, web_contents->GetView()->GetContainerSize()); |
| 2559 } | 2559 } |
| OLD | NEW |