| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_CONTENTS_CONTAINER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_CONTENTS_CONTAINER_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_CONTENTS_CONTAINER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_CONTENTS_CONTAINER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "chrome/common/instant_types.h" | |
| 13 #include "chrome/common/search_types.h" | |
| 14 #include "ui/views/controls/webview/webview.h" | 12 #include "ui/views/controls/webview/webview.h" |
| 15 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
| 16 | 14 |
| 17 namespace content { | 15 namespace content { |
| 18 class WebContents; | 16 class WebContents; |
| 19 } | 17 } |
| 20 | 18 |
| 21 namespace gfx { | 19 namespace gfx { |
| 22 class Rect; | 20 class Rect; |
| 23 } | 21 } |
| 24 | 22 |
| 25 // ContentsContainer is responsible for managing the WebContents views. | 23 // ContentsContainer is responsible for managing the WebContents views. |
| 26 // ContentsContainer has up to two children: one for the currently active | 24 // ContentsContainer has up to two children: one for the currently active |
| 27 // WebContents and one for Instant's WebContents. | 25 // WebContents and one for Instant's WebContents. |
| 28 class ContentsContainer : public views::View { | 26 class ContentsContainer : public views::View { |
| 29 public: | 27 public: |
| 30 // Internal class name | 28 // Internal class name |
| 31 static const char kViewClassName[]; | 29 static const char kViewClassName[]; |
| 32 | 30 |
| 33 explicit ContentsContainer(views::WebView* active); | 31 explicit ContentsContainer(views::WebView* active); |
| 34 virtual ~ContentsContainer(); | 32 virtual ~ContentsContainer(); |
| 35 | 33 |
| 36 // Makes the preview view the active view and nulls out the old active view. | 34 // Makes the overlay view the active view and nulls out the old active view. |
| 37 // The caller must delete or remove the old active view separately. | 35 // The caller must delete or remove the old active view separately. |
| 38 void MakePreviewContentsActiveContents(); | 36 void MakeOverlayContentsActiveContents(); |
| 39 | 37 |
| 40 // Sets the preview view. This does not delete the old. | 38 // Sets the overlay view. This does not delete the old. |
| 41 void SetPreview(views::WebView* preview, | 39 void SetOverlay(views::WebView* overlay, |
| 42 content::WebContents* preview_web_contents, | 40 content::WebContents* overlay_web_contents, |
| 43 const chrome::search::Mode& search_mode, | |
| 44 int height, | 41 int height, |
| 45 InstantSizeUnits units, | 42 bool is_height_in_pixels, |
| 46 bool draw_drop_shadow); | 43 bool draw_drop_shadow); |
| 47 | 44 |
| 48 // When the active content is reset and we have a visible preview, | 45 content::WebContents* overlay_web_contents() const { |
| 49 // the preview must be stacked back at top. | 46 return overlay_web_contents_; |
| 50 void MaybeStackPreviewAtTop(); | |
| 51 | |
| 52 content::WebContents* preview_web_contents() const { | |
| 53 return preview_web_contents_; | |
| 54 } | 47 } |
| 55 | 48 |
| 56 int preview_height() const { | 49 int overlay_height() const { |
| 57 return preview_ ? preview_->bounds().height() : 0; | 50 return overlay_ ? overlay_->bounds().height() : 0; |
| 58 } | 51 } |
| 59 | 52 |
| 60 // Sets the active top margin; the active WebView's y origin would be | 53 // Sets the active top margin; the active WebView's y origin would be |
| 61 // positioned at this |margin|, causing the active WebView to be pushed down | 54 // positioned at this |margin|, causing the active WebView to be pushed down |
| 62 // vertically by |margin| pixels in the |ContentsContainer|. | 55 // vertically by |margin| pixels in the |ContentsContainer|. |
| 63 void SetActiveTopMargin(int margin); | 56 void SetActiveTopMargin(int margin); |
| 64 | 57 |
| 65 // Returns the bounds the preview would be shown at. | 58 // Returns the bounds the overlay would be shown at. |
| 66 gfx::Rect GetPreviewBounds() const; | 59 gfx::Rect GetOverlayBounds() const; |
| 67 | 60 |
| 68 // Returns true if preview occupies full height of content page. | 61 // Returns true if overlay occupies full height of content page. |
| 69 bool IsPreviewFullHeight(int preview_height, | 62 bool IsOverlayFullHeight(int overlay_height, bool is_height_in_pixels) const; |
| 70 InstantSizeUnits preview_height_units) const; | |
| 71 | 63 |
| 72 private: | 64 private: |
| 73 // Returns true if |shadow_view_| was a child of |ContentsContainer| and | 65 // Returns true if |shadow_view_| was a child of |ContentsContainer| and |
| 74 // successfully removed from view hierarchy. | 66 // successfully removed from view hierarchy. |
| 75 // If |delete_view| is true, |shadow_view_| is deleted regardless if it is a | 67 // If |delete_view| is true, |shadow_view_| is deleted regardless if it is a |
| 76 // child of |ContentsContainer|. | 68 // child of |ContentsContainer|. |
| 77 bool RemoveShadowView(bool delete_view); | 69 bool RemoveShadowView(bool delete_view); |
| 78 | 70 |
| 79 // Overridden from views::View: | 71 // Overridden from views::View: |
| 80 virtual void Layout() OVERRIDE; | 72 virtual void Layout() OVERRIDE; |
| 81 virtual std::string GetClassName() const OVERRIDE; | 73 virtual std::string GetClassName() const OVERRIDE; |
| 82 | 74 |
| 83 views::WebView* active_; | 75 views::WebView* active_; |
| 84 views::WebView* preview_; | 76 views::WebView* overlay_; |
| 85 scoped_ptr<views::View> shadow_view_; | 77 scoped_ptr<views::View> shadow_view_; |
| 86 content::WebContents* preview_web_contents_; | 78 content::WebContents* overlay_web_contents_; |
| 87 chrome::search::Mode search_mode_; | |
| 88 bool draw_drop_shadow_; | 79 bool draw_drop_shadow_; |
| 89 | 80 |
| 90 // The margin between the top and the active view. This is used to make the | 81 // The margin between the top and the active view. This is used to make the |
| 91 // preview overlap the bookmark bar on the new tab page. | 82 // overlay overlap the bookmark bar on the new tab page. |
| 92 int active_top_margin_; | 83 int active_top_margin_; |
| 93 | 84 |
| 94 // The desired height of the preview and units. | 85 // The desired height of the overlay and whether it's in pixels or percent. |
| 95 int preview_height_; | 86 int overlay_height_; |
| 96 InstantSizeUnits preview_height_units_; | 87 bool is_height_in_pixels_; |
| 97 | 88 |
| 98 DISALLOW_COPY_AND_ASSIGN(ContentsContainer); | 89 DISALLOW_COPY_AND_ASSIGN(ContentsContainer); |
| 99 }; | 90 }; |
| 100 | 91 |
| 101 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_CONTENTS_CONTAINER_H_ | 92 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_CONTENTS_CONTAINER_H_ |
| OLD | NEW |