Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/browser/ui/views/frame/contents_container.cc

Issue 10915217: Hook up SetInstantPreviewHeight for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move height to ShowPreview. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/ui/views/frame/contents_container.h" 5 #include "chrome/browser/ui/views/frame/contents_container.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/views/controls/webview/webview.h" 8 #include "ui/views/controls/webview/webview.h"
9 9
10 using content::WebContents; 10 using content::WebContents;
11 11
12 // static 12 // static
13 const char ContentsContainer::kViewClassName[] = 13 const char ContentsContainer::kViewClassName[] =
14 "browser/ui/views/frame/ContentsContainer"; 14 "browser/ui/views/frame/ContentsContainer";
15 15
16 ContentsContainer::ContentsContainer(views::WebView* active) 16 ContentsContainer::ContentsContainer(views::WebView* active)
17 : active_(active), 17 : active_(active),
18 overlay_(NULL), 18 overlay_(NULL),
19 preview_(NULL), 19 preview_(NULL),
20 preview_web_contents_(NULL), 20 preview_web_contents_(NULL),
21 active_top_margin_(0) { 21 active_top_margin_(0),
22 preview_height_(100),
23 preview_height_units_(INSTANT_SIZE_PERCENT) {
22 AddChildView(active_); 24 AddChildView(active_);
23 } 25 }
24 26
25 ContentsContainer::~ContentsContainer() { 27 ContentsContainer::~ContentsContainer() {
26 } 28 }
27 29
28 void ContentsContainer::SetActive(views::WebView* active) { 30 void ContentsContainer::SetActive(views::WebView* active) {
29 if (active_) 31 if (active_)
30 RemoveChildView(active_); 32 RemoveChildView(active_);
31 active_ = active; 33 active_ = active;
(...skipping 15 matching lines...) Expand all
47 void ContentsContainer::MakePreviewContentsActiveContents() { 49 void ContentsContainer::MakePreviewContentsActiveContents() {
48 DCHECK(preview_); 50 DCHECK(preview_);
49 51
50 active_ = preview_; 52 active_ = preview_;
51 preview_ = NULL; 53 preview_ = NULL;
52 preview_web_contents_ = NULL; 54 preview_web_contents_ = NULL;
53 Layout(); 55 Layout();
54 } 56 }
55 57
56 void ContentsContainer::SetPreview(views::WebView* preview, 58 void ContentsContainer::SetPreview(views::WebView* preview,
57 WebContents* preview_web_contents) { 59 WebContents* preview_web_contents,
58 if (preview == preview_) 60 int height,
61 InstantSizeUnits units) {
62 if (preview == preview_ &&
63 height == preview_height_ && units == preview_height_units_)
59 return; 64 return;
60 65
61 if (preview_) 66 if (preview_)
62 RemoveChildView(preview_); 67 RemoveChildView(preview_);
63 preview_ = preview; 68 preview_ = preview;
64 preview_web_contents_ = preview_web_contents; 69 preview_web_contents_ = preview_web_contents;
70 preview_height_ = height;
71 preview_height_units_ = units;
65 if (preview_) 72 if (preview_)
66 AddChildView(preview_); 73 AddChildView(preview_);
67
68 Layout(); 74 Layout();
sreeram 2012/09/19 19:59:52 This method needs to be slightly different: void
Jered 2012/09/19 20:22:18 Done.
69 } 75 }
70 76
71 void ContentsContainer::SetActiveTopMargin(int margin) { 77 void ContentsContainer::SetActiveTopMargin(int margin) {
72 if (active_top_margin_ == margin) 78 if (active_top_margin_ == margin)
73 return; 79 return;
74 80
75 active_top_margin_ = margin; 81 active_top_margin_ = margin;
76 // Make sure we layout next time around. We need this in case our bounds 82 // Make sure we layout next time around. We need this in case our bounds
77 // haven't changed. 83 // haven't changed.
78 InvalidateLayout(); 84 InvalidateLayout();
79 } 85 }
80 86
81 gfx::Rect ContentsContainer::GetPreviewBounds() { 87 gfx::Rect ContentsContainer::GetPreviewBounds() {
82 gfx::Point screen_loc; 88 gfx::Point screen_loc;
83 ConvertPointToScreen(this, &screen_loc); 89 ConvertPointToScreen(this, &screen_loc);
84 return gfx::Rect(screen_loc, size()); 90 return gfx::Rect(screen_loc, size());
85 } 91 }
86 92
87 void ContentsContainer::Layout() { 93 void ContentsContainer::Layout() {
88 int content_y = active_top_margin_; 94 int content_y = active_top_margin_;
89 int content_height = std::max(0, height() - content_y); 95 int content_height = std::max(0, height() - content_y);
90 96
91 if (active_) 97 if (active_)
92 active_->SetBounds(0, content_y, width(), content_height); 98 active_->SetBounds(0, content_y, width(), content_height);
93 99
94 if (overlay_) 100 if (overlay_)
95 overlay_->SetBounds(0, 0, width(), height()); 101 overlay_->SetBounds(0, 0, width(), height());
96 102
97 if (preview_) 103 if (preview_)
98 preview_->SetBounds(0, 0, width(), height()); 104 preview_->SetBounds(0, 0, width(), PreviewHeightInPixels());
99 105
100 // Need to invoke views::View in case any views whose bounds didn't change 106 // Need to invoke views::View in case any views whose bounds didn't change
101 // still need a layout. 107 // still need a layout.
102 views::View::Layout(); 108 views::View::Layout();
103 } 109 }
104 110
111 int ContentsContainer::PreviewHeightInPixels() const {
112 switch (preview_height_units_) {
113 case INSTANT_SIZE_PERCENT:
114 return std::min(height(), (height() * preview_height_) / 100);
115
116 case INSTANT_SIZE_PIXELS:
117 return std::min(height(), preview_height_);
118 }
119 NOTREACHED() << "unknown units: " << preview_height_units_;
120 return 0;
121 }
122
105 std::string ContentsContainer::GetClassName() const { 123 std::string ContentsContainer::GetClassName() const {
106 return kViewClassName; 124 return kViewClassName;
107 } 125 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/contents_container.h ('k') | chrome/test/base/test_browser_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698