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

Side by Side Diff: chrome/browser/views/toolbar_view.cc

Issue 3056003: Attemp 2 at: (Closed)
Patch Set: Fix chromeos breakage Created 10 years, 5 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
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | chrome/common/extensions/extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/toolbar_view.h" 5 #include "chrome/browser/views/toolbar_view.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Separation between the location bar and the menus. 51 // Separation between the location bar and the menus.
52 static const int kMenuButtonOffset = 3; 52 static const int kMenuButtonOffset = 3;
53 53
54 // Padding to the right of the location bar 54 // Padding to the right of the location bar
55 static const int kPaddingRight = 2; 55 static const int kPaddingRight = 2;
56 56
57 static const int kPopupTopSpacingNonGlass = 3; 57 static const int kPopupTopSpacingNonGlass = 3;
58 static const int kPopupBottomSpacingNonGlass = 2; 58 static const int kPopupBottomSpacingNonGlass = 2;
59 static const int kPopupBottomSpacingGlass = 1; 59 static const int kPopupBottomSpacingGlass = 1;
60 60
61 // The height of the toolbar when it is in collapsed mode.
62 const int kCollapsedToolbarHeight = 7;
63
64 static SkBitmap* kPopupBackgroundEdge = NULL; 61 static SkBitmap* kPopupBackgroundEdge = NULL;
65 62
66 //////////////////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////////////////
67 // ToolbarView, public: 64 // ToolbarView, public:
68 65
69 ToolbarView::ToolbarView(Browser* browser) 66 ToolbarView::ToolbarView(Browser* browser)
70 : model_(browser->toolbar_model()), 67 : model_(browser->toolbar_model()),
71 back_(NULL), 68 back_(NULL),
72 forward_(NULL), 69 forward_(NULL),
73 home_(NULL), 70 home_(NULL),
74 reload_(NULL), 71 reload_(NULL),
75 location_bar_(NULL), 72 location_bar_(NULL),
76 browser_actions_(NULL), 73 browser_actions_(NULL),
77 app_menu_(NULL), 74 app_menu_(NULL),
78 profile_(NULL), 75 profile_(NULL),
79 browser_(browser), 76 browser_(browser),
80 profiles_menu_contents_(NULL), 77 profiles_menu_contents_(NULL),
81 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 78 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
82 destroyed_flag_(NULL), 79 destroyed_flag_(NULL) {
83 collapsed_(false) {
84 SetID(VIEW_ID_TOOLBAR); 80 SetID(VIEW_ID_TOOLBAR);
85 81
86 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); 82 browser_->command_updater()->AddCommandObserver(IDC_BACK, this);
87 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); 83 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this);
88 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); 84 browser_->command_updater()->AddCommandObserver(IDC_HOME, this);
89 85
90 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? 86 display_mode_ = browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ?
91 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION; 87 DISPLAYMODE_NORMAL : DISPLAYMODE_LOCATION;
92 88
93 if (!kPopupBackgroundEdge) { 89 if (!kPopupBackgroundEdge) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void ToolbarView::RemoveMenuListener(views::MenuListener* listener) { 212 void ToolbarView::RemoveMenuListener(views::MenuListener* listener) {
217 for (std::vector<views::MenuListener*>::iterator i(menu_listeners_.begin()); 213 for (std::vector<views::MenuListener*>::iterator i(menu_listeners_.begin());
218 i != menu_listeners_.end(); ++i) { 214 i != menu_listeners_.end(); ++i) {
219 if (*i == listener) { 215 if (*i == listener) {
220 menu_listeners_.erase(i); 216 menu_listeners_.erase(i);
221 return; 217 return;
222 } 218 }
223 } 219 }
224 } 220 }
225 221
226 void ToolbarView::SetCollapsed(bool val) {
227 if (collapsed_ == val)
228 return;
229
230 collapsed_ = val;
231
232 // When switching to and from collapsed view, we need to force hide/show the
233 // location bar entry view, like we do when we switch to full screen mode in
234 // BrowserView::ProcessFullscreen. Otherwise the text view can appear floating
235 // on top of web content.
236 if (collapsed_)
237 location_bar_->PushForceHidden();
238 else
239 location_bar_->PopForceHidden();
240 }
241
242 //////////////////////////////////////////////////////////////////////////////// 222 ////////////////////////////////////////////////////////////////////////////////
243 // ToolbarView, AccessibleToolbarView overrides: 223 // ToolbarView, AccessibleToolbarView overrides:
244 224
245 bool ToolbarView::SetToolbarFocus( 225 bool ToolbarView::SetToolbarFocus(
246 int view_storage_id, views::View* initial_focus) { 226 int view_storage_id, views::View* initial_focus) {
247 if (!AccessibleToolbarView::SetToolbarFocus(view_storage_id, initial_focus)) 227 if (!AccessibleToolbarView::SetToolbarFocus(view_storage_id, initial_focus))
248 return false; 228 return false;
249 229
250 location_bar_->SetShowFocusRect(true); 230 location_bar_->SetShowFocusRect(true);
251 return true; 231 return true;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 browser_actions_->GetPreferredSize().width() + 389 browser_actions_->GetPreferredSize().width() +
410 kMenuButtonOffset + 390 kMenuButtonOffset +
411 app_menu_->GetPreferredSize().width() + kPaddingRight; 391 app_menu_->GetPreferredSize().width() + kPaddingRight;
412 392
413 static SkBitmap normal_background; 393 static SkBitmap normal_background;
414 if (normal_background.isNull()) { 394 if (normal_background.isNull()) {
415 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 395 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
416 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); 396 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER);
417 } 397 }
418 398
419 return gfx::Size(min_width, 399 return gfx::Size(min_width, normal_background.height());
420 collapsed_ ? kCollapsedToolbarHeight : normal_background.height());
421 } 400 }
422 401
423 int vertical_spacing = PopupTopSpacing() + 402 int vertical_spacing = PopupTopSpacing() +
424 (GetWindow()->GetNonClientView()->UseNativeFrame() ? 403 (GetWindow()->GetNonClientView()->UseNativeFrame() ?
425 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); 404 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass);
426 return gfx::Size(0, location_bar_->GetPreferredSize().height() + 405 return gfx::Size(0, location_bar_->GetPreferredSize().height() +
427 vertical_spacing); 406 vertical_spacing);
428 } 407 }
429 408
430 void ToolbarView::Layout() { 409 void ToolbarView::Layout() {
431 // If we have not been initialized yet just do nothing. 410 // If we have not been initialized yet just do nothing.
432 if (back_ == NULL) 411 if (back_ == NULL)
433 return; 412 return;
434 413
435 if (!IsDisplayModeNormal()) { 414 if (!IsDisplayModeNormal()) {
436 int edge_width = (browser_->window() && browser_->window()->IsMaximized()) ? 415 int edge_width = (browser_->window() && browser_->window()->IsMaximized()) ?
437 0 : kPopupBackgroundEdge->width(); // See Paint(). 416 0 : kPopupBackgroundEdge->width(); // See Paint().
438 location_bar_->SetBounds(edge_width, PopupTopSpacing(), 417 location_bar_->SetBounds(edge_width, PopupTopSpacing(),
439 width() - (edge_width * 2), location_bar_->GetPreferredSize().height()); 418 width() - (edge_width * 2), location_bar_->GetPreferredSize().height());
440 return; 419 return;
441 } 420 }
442 421
443 // In collapsed mode, we don't show any of the child controls.
444 for (int i = 0; i < GetChildViewCount(); ++i)
445 GetChildViewAt(i)->SetVisible(!collapsed_);
446
447 int child_y = std::min(kControlVertOffset, height()); 422 int child_y = std::min(kControlVertOffset, height());
448 // We assume all child elements are the same height. 423 // We assume all child elements are the same height.
449 int child_height = 424 int child_height =
450 std::min(back_->GetPreferredSize().height(), height() - child_y); 425 std::min(back_->GetPreferredSize().height(), height() - child_y);
451 426
452 // If the window is maximized, we extend the back button to the left so that 427 // If the window is maximized, we extend the back button to the left so that
453 // clicking on the left-most pixel will activate the back button. 428 // clicking on the left-most pixel will activate the back button.
454 // TODO(abarth): If the window becomes maximized but is not resized, 429 // TODO(abarth): If the window becomes maximized but is not resized,
455 // then Layout() might not be called and the back button 430 // then Layout() might not be called and the back button
456 // will be slightly the wrong size. We should force a 431 // will be slightly the wrong size. We should force a
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 657 }
683 #endif 658 #endif
684 659
685 // Tell the menu button to activate, opening its pop-up menu. 660 // Tell the menu button to activate, opening its pop-up menu.
686 menu_button->Activate(); 661 menu_button->Activate();
687 662
688 #if defined(OS_WIN) 663 #if defined(OS_WIN)
689 SetToolbarFocus(NULL, menu_button); 664 SetToolbarFocus(NULL, menu_button);
690 #endif 665 #endif
691 } 666 }
OLDNEW
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | chrome/common/extensions/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698