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

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

Issue 12013004: alternate ntp: unpinned bookmark bar in ntp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 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 #include "chrome/browser/ui/views/frame/contents_container.h" 5 #include "chrome/browser/ui/views/frame/contents_container.h"
6 6
7 #include "grit/theme_resources.h" 7 #include "grit/theme_resources.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/image/image_skia.h" 10 #include "ui/gfx/image/image_skia.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 } // namespace 76 } // namespace
77 77
78 ContentsContainer::ContentsContainer(views::WebView* active) 78 ContentsContainer::ContentsContainer(views::WebView* active)
79 : active_(active), 79 : active_(active),
80 preview_(NULL), 80 preview_(NULL),
81 preview_web_contents_(NULL), 81 preview_web_contents_(NULL),
82 draw_drop_shadow_(false), 82 draw_drop_shadow_(false),
83 active_top_margin_(0), 83 active_top_margin_(0),
84 preview_height_(100), 84 preview_height_(100),
85 preview_height_units_(INSTANT_SIZE_PERCENT), 85 preview_height_units_(INSTANT_SIZE_PERCENT) {
86 extra_content_height_(0) {
87 AddChildView(active_); 86 AddChildView(active_);
88 } 87 }
89 88
90 ContentsContainer::~ContentsContainer() { 89 ContentsContainer::~ContentsContainer() {
91 RemoveShadowView(true); 90 RemoveShadowView(true);
92 } 91 }
93 92
94 void ContentsContainer::MakePreviewContentsActiveContents() { 93 void ContentsContainer::MakePreviewContentsActiveContents() {
95 DCHECK(preview_); 94 DCHECK(preview_);
96 95
97 active_ = preview_; 96 active_ = preview_;
98 preview_ = NULL; 97 preview_ = NULL;
99 preview_web_contents_ = NULL; 98 preview_web_contents_ = NULL;
100 // Since |preview_| has been nuked, shadow view is not needed anymore. 99 // Since |preview_| has been nuked, shadow view is not needed anymore.
101 // Note that the previous |active_| will be deleted by caller (see 100 // Note that the previous |active_| will be deleted by caller (see
102 // BrowserView::ActiveTabChanged()) after this call, hence removing the old 101 // BrowserView::ActiveTabChanged()) after this call, hence removing the old
103 // |active_| as a child, and making the new |active_| (which is the previous 102 // |active_| as a child, and making the new |active_| (which is the previous
104 // |preview_|) the first child. 103 // |preview_|) the first child.
105 RemoveShadowView(true); 104 RemoveShadowView(true);
106 Layout(); 105 Layout();
107 } 106 }
108 107
109 void ContentsContainer::SetPreview(views::WebView* preview, 108 void ContentsContainer::SetPreview(views::WebView* preview,
110 content::WebContents* preview_web_contents, 109 content::WebContents* preview_web_contents,
110 const chrome::search::Mode& search_mode,
111 int height, 111 int height,
112 InstantSizeUnits units, 112 InstantSizeUnits units,
113 bool draw_drop_shadow) { 113 bool draw_drop_shadow) {
114 // If drawing drop shadow, clip the bottom 1-px-thick separator out of 114 // If drawing drop shadow, clip the bottom 1-px-thick separator out of
115 // preview. 115 // preview.
116 // TODO(kuan): remove this when GWS gives chrome the height without the 116 // TODO(kuan): remove this when GWS gives chrome the height without the
117 // separator. 117 // separator.
118 #if !defined(OS_WIN) 118 #if !defined(OS_WIN)
119 if (draw_drop_shadow) 119 if (draw_drop_shadow)
120 --height; 120 --height;
121 #endif // !defined(OS_WIN) 121 #endif // !defined(OS_WIN)
122 122
123 if (preview_ == preview && preview_web_contents_ == preview_web_contents && 123 if (preview_ == preview && preview_web_contents_ == preview_web_contents &&
124 preview_height_ == height && preview_height_units_ == units && 124 search_mode_ == search_mode && preview_height_ == height &&
125 draw_drop_shadow_ == draw_drop_shadow) { 125 preview_height_units_ == units && draw_drop_shadow_ == draw_drop_shadow) {
126 return; 126 return;
127 } 127 }
128 128
129 if (preview_ != preview) { 129 if (preview_ != preview) {
130 if (preview_) { 130 if (preview_) {
131 // Order of children is important: always |active_| first, then 131 // Order of children is important: always |active_| first, then
132 // |preview_|, then shadow view if necessary. To make sure the next view 132 // |preview_|, then shadow view if necessary. To make sure the next view
133 // is added in the right order, remove shadow view every time |preview_| 133 // is added in the right order, remove shadow view every time |preview_|
134 // is removed. 134 // is removed.
135 RemoveShadowView(false); 135 RemoveShadowView(false);
136 RemoveChildView(preview_); 136 RemoveChildView(preview_);
137 } 137 }
138 preview_ = preview; 138 preview_ = preview;
139 if (preview_) 139 if (preview_)
140 AddChildView(preview_); 140 AddChildView(preview_);
141 } 141 }
142 142
143 preview_web_contents_ = preview_web_contents; 143 preview_web_contents_ = preview_web_contents;
144 search_mode_ = search_mode;
144 preview_height_ = height; 145 preview_height_ = height;
145 preview_height_units_ = units; 146 preview_height_units_ = units;
146 draw_drop_shadow_ = draw_drop_shadow; 147 draw_drop_shadow_ = draw_drop_shadow;
147 148
148 // Add or remove shadow view as needed. 149 // Add or remove shadow view as needed.
149 if (preview_ && draw_drop_shadow_) { 150 if (preview_ && draw_drop_shadow_) {
150 #if !defined(OS_WIN) 151 #if !defined(OS_WIN)
151 if (!shadow_view_.get()) // Shadow view has not been created. 152 if (!shadow_view_.get()) // Shadow view has not been created.
152 shadow_view_.reset(new ShadowView()); 153 shadow_view_.reset(new ShadowView());
153 if (!shadow_view_->parent()) // Shadow view has not been added. 154 if (!shadow_view_->parent()) // Shadow view has not been added.
(...skipping 29 matching lines...) Expand all
183 // haven't changed. 184 // haven't changed.
184 InvalidateLayout(); 185 InvalidateLayout();
185 } 186 }
186 187
187 gfx::Rect ContentsContainer::GetPreviewBounds() const { 188 gfx::Rect ContentsContainer::GetPreviewBounds() const {
188 gfx::Point screen_loc; 189 gfx::Point screen_loc;
189 ConvertPointToScreen(this, &screen_loc); 190 ConvertPointToScreen(this, &screen_loc);
190 return gfx::Rect(screen_loc, size()); 191 return gfx::Rect(screen_loc, size());
191 } 192 }
192 193
193 void ContentsContainer::SetExtraContentHeight(int height) {
194 if (height == extra_content_height_)
195 return;
196 extra_content_height_ = height;
197 }
198
199 bool ContentsContainer::IsPreviewFullHeight( 194 bool ContentsContainer::IsPreviewFullHeight(
200 int preview_height, 195 int preview_height,
201 InstantSizeUnits preview_height_units) const { 196 InstantSizeUnits preview_height_units) const {
202 int height_in_pixels = PreviewHeightInPixels(height(), preview_height, 197 int height_in_pixels = PreviewHeightInPixels(height(), preview_height,
203 preview_height_units); 198 preview_height_units);
204 return height_in_pixels == height(); 199 return height_in_pixels == height();
205 } 200 }
206 201
207 void ContentsContainer::Layout() { 202 void ContentsContainer::Layout() {
208 int content_y = active_top_margin_; 203 int content_y = active_top_margin_;
209 int content_height = 204 int content_height = std::max(0, height() - content_y);
210 std::max(0, height() - content_y + extra_content_height_);
211 205
212 active_->SetBounds(0, content_y, width(), content_height); 206 active_->SetBounds(0, content_y, width(), content_height);
213 207
214 if (preview_) { 208 if (preview_) {
215 preview_->SetBounds(0, 0, width(), 209 // On NTP, preview starts where content starts vertically, in case there's
210 // a detached bookmark bar.
211 int y = search_mode_.is_ntp() ? content_y : 0;
212 preview_->SetBounds(0, y, width(),
216 PreviewHeightInPixels(height(), preview_height_, 213 PreviewHeightInPixels(height(), preview_height_,
217 preview_height_units_)); 214 preview_height_units_));
218 if (draw_drop_shadow_) { 215 if (draw_drop_shadow_) {
219 #if !defined(OS_WIN) 216 #if !defined(OS_WIN)
220 DCHECK(shadow_view_.get() && shadow_view_->parent()); 217 DCHECK(shadow_view_.get() && shadow_view_->parent());
221 shadow_view_->SetBounds(0, preview_->bounds().height(), width(), 218 shadow_view_->SetBounds(0, preview_->bounds().height(), width(),
222 shadow_view_->GetPreferredSize().height()); 219 shadow_view_->GetPreferredSize().height());
223 #endif // !defined(OS_WIN) 220 #endif // !defined(OS_WIN)
224 } 221 }
225 } 222 }
(...skipping 15 matching lines...) Expand all
241 238
242 RemoveChildView(shadow_view_.get()); 239 RemoveChildView(shadow_view_.get());
243 if (delete_view) 240 if (delete_view)
244 shadow_view_.reset(NULL); 241 shadow_view_.reset(NULL);
245 return true; 242 return true;
246 } 243 }
247 244
248 std::string ContentsContainer::GetClassName() const { 245 std::string ContentsContainer::GetClassName() const {
249 return kViewClassName; 246 return kViewClassName;
250 } 247 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/contents_container.h ('k') | chrome/browser/ui/views/frame/instant_preview_controller_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698