| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/frame/browser_view_layout.h" | 5 #include "chrome/browser/views/frame/browser_view_layout.h" |
| 6 | 6 |
| 7 #include "chrome/browser/find_bar.h" | 7 #include "chrome/browser/find_bar.h" |
| 8 #include "chrome/browser/find_bar_controller.h" | 8 #include "chrome/browser/find_bar_controller.h" |
| 9 #include "chrome/browser/view_ids.h" | 9 #include "chrome/browser/view_ids.h" |
| 10 #include "chrome/browser/views/bookmark_bar_view.h" | 10 #include "chrome/browser/views/bookmark_bar_view.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // The visible height of the shadow above the tabs. Clicks in this area are | 27 // The visible height of the shadow above the tabs. Clicks in this area are |
| 28 // treated as clicks to the frame, rather than clicks to the tab. | 28 // treated as clicks to the frame, rather than clicks to the tab. |
| 29 const int kTabShadowSize = 2; | 29 const int kTabShadowSize = 2; |
| 30 // The vertical overlap between the TabStrip and the Toolbar. | 30 // The vertical overlap between the TabStrip and the Toolbar. |
| 31 const int kToolbarTabStripVerticalOverlap = 3; | 31 const int kToolbarTabStripVerticalOverlap = 3; |
| 32 // An offset distance between certain toolbars and the toolbar that preceded | 32 // An offset distance between certain toolbars and the toolbar that preceded |
| 33 // them in layout. | 33 // them in layout. |
| 34 const int kSeparationLineHeight = 1; | 34 const int kSeparationLineHeight = 1; |
| 35 // Spacing between extension app icon and title. | |
| 36 const int kExtensionAppIconTitleSpacing = 4; | |
| 37 | 35 |
| 38 } // namespace | 36 } // namespace |
| 39 | 37 |
| 40 //////////////////////////////////////////////////////////////////////////////// | 38 //////////////////////////////////////////////////////////////////////////////// |
| 41 // BrowserViewLayout, public: | 39 // BrowserViewLayout, public: |
| 42 | 40 |
| 43 BrowserViewLayout::BrowserViewLayout() | 41 BrowserViewLayout::BrowserViewLayout() |
| 44 : extension_app_icon_(NULL), | 42 : tabstrip_(NULL), |
| 45 extension_app_title_(NULL), | |
| 46 tabstrip_(NULL), | |
| 47 toolbar_(NULL), | 43 toolbar_(NULL), |
| 48 contents_split_(NULL), | 44 contents_split_(NULL), |
| 49 contents_container_(NULL), | 45 contents_container_(NULL), |
| 50 infobar_container_(NULL), | 46 infobar_container_(NULL), |
| 51 download_shelf_(NULL), | 47 download_shelf_(NULL), |
| 52 extension_shelf_(NULL), | 48 extension_shelf_(NULL), |
| 53 active_bookmark_bar_(NULL), | 49 active_bookmark_bar_(NULL), |
| 54 browser_view_(NULL), | 50 browser_view_(NULL), |
| 55 find_bar_y_(0) { | 51 find_bar_y_(0) { |
| 56 } | 52 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 195 |
| 200 void BrowserViewLayout::Installed(views::View* host) { | 196 void BrowserViewLayout::Installed(views::View* host) { |
| 201 toolbar_ = NULL; | 197 toolbar_ = NULL; |
| 202 contents_split_ = NULL; | 198 contents_split_ = NULL; |
| 203 contents_container_ = NULL; | 199 contents_container_ = NULL; |
| 204 infobar_container_ = NULL; | 200 infobar_container_ = NULL; |
| 205 download_shelf_ = NULL; | 201 download_shelf_ = NULL; |
| 206 extension_shelf_ = NULL; | 202 extension_shelf_ = NULL; |
| 207 active_bookmark_bar_ = NULL; | 203 active_bookmark_bar_ = NULL; |
| 208 tabstrip_ = NULL; | 204 tabstrip_ = NULL; |
| 209 extension_app_icon_ = NULL; | |
| 210 extension_app_title_ = NULL; | |
| 211 browser_view_ = static_cast<BrowserView*>(host); | 205 browser_view_ = static_cast<BrowserView*>(host); |
| 212 } | 206 } |
| 213 | 207 |
| 214 void BrowserViewLayout::Uninstalled(views::View* host) {} | 208 void BrowserViewLayout::Uninstalled(views::View* host) {} |
| 215 | 209 |
| 216 void BrowserViewLayout::ViewAdded(views::View* host, views::View* view) { | 210 void BrowserViewLayout::ViewAdded(views::View* host, views::View* view) { |
| 217 switch (view->GetID()) { | 211 switch (view->GetID()) { |
| 218 case VIEW_ID_CONTENTS_SPLIT: | 212 case VIEW_ID_CONTENTS_SPLIT: |
| 219 contents_split_ = view; | 213 contents_split_ = view; |
| 220 contents_container_ = contents_split_->GetChildViewAt(0); | 214 contents_container_ = contents_split_->GetChildViewAt(0); |
| 221 break; | 215 break; |
| 222 case VIEW_ID_INFO_BAR_CONTAINER: | 216 case VIEW_ID_INFO_BAR_CONTAINER: |
| 223 infobar_container_ = view; | 217 infobar_container_ = view; |
| 224 break; | 218 break; |
| 225 case VIEW_ID_DOWNLOAD_SHELF: | 219 case VIEW_ID_DOWNLOAD_SHELF: |
| 226 download_shelf_ = static_cast<DownloadShelfView*>(view); | 220 download_shelf_ = static_cast<DownloadShelfView*>(view); |
| 227 break; | 221 break; |
| 228 case VIEW_ID_DEV_EXTENSION_SHELF: | 222 case VIEW_ID_DEV_EXTENSION_SHELF: |
| 229 extension_shelf_ = static_cast<ExtensionShelf*>(view); | 223 extension_shelf_ = static_cast<ExtensionShelf*>(view); |
| 230 break; | 224 break; |
| 231 case VIEW_ID_BOOKMARK_BAR: | 225 case VIEW_ID_BOOKMARK_BAR: |
| 232 active_bookmark_bar_ = static_cast<BookmarkBarView*>(view); | 226 active_bookmark_bar_ = static_cast<BookmarkBarView*>(view); |
| 233 break; | 227 break; |
| 234 case VIEW_ID_TOOLBAR: | 228 case VIEW_ID_TOOLBAR: |
| 235 toolbar_ = static_cast<ToolbarView*>(view); | 229 toolbar_ = static_cast<ToolbarView*>(view); |
| 236 break; | 230 break; |
| 237 case VIEW_ID_TAB_STRIP: | 231 case VIEW_ID_TAB_STRIP: |
| 238 tabstrip_ = static_cast<BaseTabStrip*>(view); | 232 tabstrip_ = static_cast<BaseTabStrip*>(view); |
| 239 break; | 233 break; |
| 240 case VIEW_ID_EXTENSION_APP_ICON: | |
| 241 extension_app_icon_ = static_cast<views::ImageView*>(view); | |
| 242 break; | |
| 243 case VIEW_ID_EXTENSION_APP_TITLE: | |
| 244 extension_app_title_ = static_cast<views::Label*>(view); | |
| 245 break; | |
| 246 } | 234 } |
| 247 } | 235 } |
| 248 | 236 |
| 249 void BrowserViewLayout::ViewRemoved(views::View* host, views::View* view) { | 237 void BrowserViewLayout::ViewRemoved(views::View* host, views::View* view) { |
| 250 switch (view->GetID()) { | 238 switch (view->GetID()) { |
| 251 case VIEW_ID_BOOKMARK_BAR: | 239 case VIEW_ID_BOOKMARK_BAR: |
| 252 active_bookmark_bar_ = NULL; | 240 active_bookmark_bar_ = NULL; |
| 253 break; | 241 break; |
| 254 } | 242 } |
| 255 } | 243 } |
| 256 | 244 |
| 257 void BrowserViewLayout::Layout(views::View* host) { | 245 void BrowserViewLayout::Layout(views::View* host) { |
| 258 vertical_layout_rect_ = browser_view_->GetLocalBounds(true); | 246 vertical_layout_rect_ = browser_view_->GetLocalBounds(true); |
| 259 LayoutExtensionAppIconAndTitle(); | |
| 260 int top = LayoutTabStrip(); | 247 int top = LayoutTabStrip(); |
| 261 top = LayoutToolbar(top); | 248 top = LayoutToolbar(top); |
| 262 top = LayoutBookmarkAndInfoBars(top); | 249 top = LayoutBookmarkAndInfoBars(top); |
| 263 int bottom = LayoutExtensionAndDownloadShelves(); | 250 int bottom = LayoutExtensionAndDownloadShelves(); |
| 264 LayoutTabContents(top, bottom); | 251 LayoutTabContents(top, bottom); |
| 265 // This must be done _after_ we lay out the TabContents since this | 252 // This must be done _after_ we lay out the TabContents since this |
| 266 // code calls back into us to find the bounding box the find bar | 253 // code calls back into us to find the bounding box the find bar |
| 267 // must be laid out within, and that code depends on the | 254 // must be laid out within, and that code depends on the |
| 268 // TabContentsContainer's bounds being up to date. | 255 // TabContentsContainer's bounds being up to date. |
| 269 if (browser()->HasFindBarController()) { | 256 if (browser()->HasFindBarController()) { |
| 270 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( | 257 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( |
| 271 gfx::Rect(), true); | 258 gfx::Rect(), true); |
| 272 } | 259 } |
| 273 // Align status bubble with the bottom of the contents_container. | 260 // Align status bubble with the bottom of the contents_container. |
| 274 browser_view_->LayoutStatusBubble( | 261 browser_view_->LayoutStatusBubble( |
| 275 top + contents_container_->bounds().height()); | 262 top + contents_container_->bounds().height()); |
| 276 browser_view_->SchedulePaint(); | 263 browser_view_->SchedulePaint(); |
| 277 } | 264 } |
| 278 | 265 |
| 279 // Return the preferred size which is the size required to give each | 266 // Return the preferred size which is the size required to give each |
| 280 // children their respective preferred size. | 267 // children their respective preferred size. |
| 281 gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) { | 268 gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) { |
| 282 return gfx::Size(); | 269 return gfx::Size(); |
| 283 } | 270 } |
| 284 | 271 |
| 285 ////////////////////////////////////////////////////////////////////////////// | 272 ////////////////////////////////////////////////////////////////////////////// |
| 286 // BrowserViewLayout, private: | 273 // BrowserViewLayout, private: |
| 287 | 274 |
| 288 void BrowserViewLayout::LayoutExtensionAppIconAndTitle() { | |
| 289 if (browser_view_->browser()->type() != Browser::TYPE_EXTENSION_APP) | |
| 290 return; | |
| 291 | |
| 292 extension_app_icon_->SetVisible(true); | |
| 293 extension_app_icon_->SetBounds(0, 0, Extension::EXTENSION_ICON_SMALL, | |
| 294 Extension::EXTENSION_ICON_SMALL); | |
| 295 | |
| 296 extension_app_title_->SetVisible(true); | |
| 297 | |
| 298 // Position the title vertically centered with the icon and slightly to its | |
| 299 // right. | |
| 300 extension_app_title_->SetX( | |
| 301 extension_app_icon_->x() + extension_app_icon_->width() + | |
| 302 kExtensionAppIconTitleSpacing); | |
| 303 extension_app_title_->SetY( | |
| 304 extension_app_icon_->y() + | |
| 305 ((extension_app_icon_->height() - extension_app_title_->height()) / 2)); | |
| 306 } | |
| 307 | |
| 308 int BrowserViewLayout::LayoutTabStrip() { | 275 int BrowserViewLayout::LayoutTabStrip() { |
| 309 if (!browser_view_->IsTabStripVisible()) { | 276 if (!browser_view_->IsTabStripVisible()) { |
| 310 tabstrip_->SetVisible(false); | 277 tabstrip_->SetVisible(false); |
| 311 tabstrip_->SetBounds(0, 0, 0, 0); | 278 tabstrip_->SetBounds(0, 0, 0, 0); |
| 312 return 0; | 279 return 0; |
| 313 } | 280 } |
| 314 gfx::Rect layout_bounds = | 281 gfx::Rect layout_bounds = |
| 315 browser_view_->frame()->GetBoundsForTabStrip(tabstrip_); | 282 browser_view_->frame()->GetBoundsForTabStrip(tabstrip_); |
| 316 | 283 |
| 317 if (browser_view_->UseVerticalTabs()) { | 284 if (browser_view_->UseVerticalTabs()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 336 | 303 |
| 337 int BrowserViewLayout::LayoutToolbar(int top) { | 304 int BrowserViewLayout::LayoutToolbar(int top) { |
| 338 int browser_view_width = vertical_layout_rect_.width(); | 305 int browser_view_width = vertical_layout_rect_.width(); |
| 339 bool visible = browser_view_->IsToolbarVisible(); | 306 bool visible = browser_view_->IsToolbarVisible(); |
| 340 toolbar_->location_bar()->SetFocusable(visible); | 307 toolbar_->location_bar()->SetFocusable(visible); |
| 341 int y = top; | 308 int y = top; |
| 342 if (!browser_view_->UseVerticalTabs()) { | 309 if (!browser_view_->UseVerticalTabs()) { |
| 343 y -= ((visible && browser_view_->IsTabStripVisible()) ? | 310 y -= ((visible && browser_view_->IsTabStripVisible()) ? |
| 344 kToolbarTabStripVerticalOverlap : 0); | 311 kToolbarTabStripVerticalOverlap : 0); |
| 345 } | 312 } |
| 346 | 313 int height = visible ? toolbar_->GetPreferredSize().height() : 0; |
| 347 int height = 0; | 314 toolbar_->SetVisible(visible); |
| 348 if (visible) { | |
| 349 height = toolbar_->GetPreferredSize().height(); | |
| 350 toolbar_->SetVisible(true); | |
| 351 } else { | |
| 352 toolbar_->SetVisible(false); | |
| 353 } | |
| 354 | |
| 355 toolbar_->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); | 315 toolbar_->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); |
| 356 return y + height; | 316 return y + height; |
| 357 } | 317 } |
| 358 | 318 |
| 359 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) { | 319 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) { |
| 360 find_bar_y_ = top + browser_view_->y() - 1; | 320 find_bar_y_ = top + browser_view_->y() - 1; |
| 361 if (active_bookmark_bar_) { | 321 if (active_bookmark_bar_) { |
| 362 // If we're showing the Bookmark bar in detached style, then we | 322 // If we're showing the Bookmark bar in detached style, then we |
| 363 // need to show any Info bar _above_ the Bookmark bar, since the | 323 // need to show any Info bar _above_ the Bookmark bar, since the |
| 364 // Bookmark bar is styled to look like it's part of the page. | 324 // Bookmark bar is styled to look like it's part of the page. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 int height = | 411 int height = |
| 452 visible ? extension_shelf_->GetPreferredSize().height() : 0; | 412 visible ? extension_shelf_->GetPreferredSize().height() : 0; |
| 453 extension_shelf_->SetVisible(visible && height != 0); | 413 extension_shelf_->SetVisible(visible && height != 0); |
| 454 extension_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, | 414 extension_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, |
| 455 vertical_layout_rect_.width(), height); | 415 vertical_layout_rect_.width(), height); |
| 456 extension_shelf_->Layout(); | 416 extension_shelf_->Layout(); |
| 457 bottom -= height; | 417 bottom -= height; |
| 458 } | 418 } |
| 459 return bottom; | 419 return bottom; |
| 460 } | 420 } |
| OLD | NEW |