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

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

Issue 28072: Make non-glass popups match new mockup from Glen.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 static const int kControlVertOffset = 6; 54 static const int kControlVertOffset = 6;
55 static const int kControlIndent = 3; 55 static const int kControlIndent = 3;
56 static const int kStatusBubbleWidth = 480; 56 static const int kStatusBubbleWidth = 480;
57 57
58 // Separation between the location bar and the menus. 58 // Separation between the location bar and the menus.
59 static const int kMenuButtonOffset = 3; 59 static const int kMenuButtonOffset = 3;
60 60
61 // Padding to the right of the location bar 61 // Padding to the right of the location bar
62 static const int kPaddingRight = 2; 62 static const int kPaddingRight = 2;
63 63
64 static const int kPopupTopSpacingNonGlass = 3;
65 static const int kPopupBottomSpacingNonGlass = 2;
66 static const int kPopupBottomSpacingGlass = 1;
67
68 static SkBitmap* kPopupBackgroundEdge = NULL;
69
64 BrowserToolbarView::BrowserToolbarView(Browser* browser) 70 BrowserToolbarView::BrowserToolbarView(Browser* browser)
65 : EncodingMenuControllerDelegate(browser), 71 : EncodingMenuControllerDelegate(browser),
66 model_(browser->toolbar_model()), 72 model_(browser->toolbar_model()),
67 back_(NULL), 73 back_(NULL),
68 forward_(NULL), 74 forward_(NULL),
69 reload_(NULL), 75 reload_(NULL),
70 home_(NULL), 76 home_(NULL),
71 star_(NULL), 77 star_(NULL),
72 location_bar_(NULL), 78 location_bar_(NULL),
73 go_(NULL), 79 go_(NULL),
74 profile_(NULL), 80 profile_(NULL),
75 acc_focused_view_(NULL), 81 acc_focused_view_(NULL),
76 browser_(browser), 82 browser_(browser),
77 tab_(NULL), 83 tab_(NULL),
78 profiles_helper_(new GetProfilesHelper(this)), 84 profiles_helper_(new GetProfilesHelper(this)),
79 profiles_menu_(NULL) { 85 profiles_menu_(NULL) {
80 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); 86 browser_->command_updater()->AddCommandObserver(IDC_BACK, this);
81 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); 87 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this);
82 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); 88 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this);
83 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); 89 browser_->command_updater()->AddCommandObserver(IDC_HOME, this);
84 browser_->command_updater()->AddCommandObserver(IDC_STAR, this); 90 browser_->command_updater()->AddCommandObserver(IDC_STAR, this);
85 back_menu_model_.reset(new BackForwardMenuModelWin( 91 back_menu_model_.reset(new BackForwardMenuModelWin(
86 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); 92 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE));
87 forward_menu_model_.reset(new BackForwardMenuModelWin( 93 forward_menu_model_.reset(new BackForwardMenuModelWin(
88 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); 94 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE));
89 if (browser->type() == Browser::TYPE_NORMAL) 95 if (browser->type() == Browser::TYPE_NORMAL)
90 display_mode_ = DISPLAYMODE_NORMAL; 96 display_mode_ = DISPLAYMODE_NORMAL;
91 else 97 else
92 display_mode_ = DISPLAYMODE_LOCATION; 98 display_mode_ = DISPLAYMODE_LOCATION;
99
100 if (!kPopupBackgroundEdge) {
101 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed(
102 IDR_LOCATIONBG_POPUPMODE_EDGE);
103 }
93 } 104 }
94 105
95 BrowserToolbarView::~BrowserToolbarView() { 106 BrowserToolbarView::~BrowserToolbarView() {
96 profiles_helper_->OnDelegateDeleted(); 107 profiles_helper_->OnDelegateDeleted();
97 } 108 }
98 109
99 void BrowserToolbarView::Init(Profile* profile) { 110 void BrowserToolbarView::Init(Profile* profile) {
100 // Create all the individual Views in the Toolbar. 111 // Create all the individual Views in the Toolbar.
101 CreateLeftSideControls(); 112 CreateLeftSideControls();
102 CreateCenterStack(profile); 113 CreateCenterStack(profile);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 app_menu_->SetID(VIEW_ID_APP_MENU); 263 app_menu_->SetID(VIEW_ID_APP_MENU);
253 AddChildView(app_menu_); 264 AddChildView(app_menu_);
254 } 265 }
255 266
256 void BrowserToolbarView::Layout() { 267 void BrowserToolbarView::Layout() {
257 // If we have not been initialized yet just do nothing. 268 // If we have not been initialized yet just do nothing.
258 if (back_ == NULL) 269 if (back_ == NULL)
259 return; 270 return;
260 271
261 if (!IsDisplayModeNormal()) { 272 if (!IsDisplayModeNormal()) {
262 location_bar_->SetBounds(0, 0, width(), 273 int edge_width = (browser_->window() && browser_->window()->IsMaximized()) ?
263 location_bar_->GetPreferredSize().height()); 274 0 : kPopupBackgroundEdge->width(); // See Paint().
275 location_bar_->SetBounds(edge_width, PopupTopSpacing(),
276 width() - (edge_width * 2), location_bar_->GetPreferredSize().height());
264 return; 277 return;
265 } 278 }
266 279
267 int child_y = std::min(kControlVertOffset, height()); 280 int child_y = std::min(kControlVertOffset, height());
268 // We assume all child elements are the same height. 281 // We assume all child elements are the same height.
269 int child_height = 282 int child_height =
270 std::min(go_->GetPreferredSize().height(), height() - child_y); 283 std::min(go_->GetPreferredSize().height(), height() - child_y);
271 284
272 // If the window is maximized, we extend the back button to the left so that 285 // If the window is maximized, we extend the back button to the left so that
273 // clicking on the left-most pixel will activate the back button. 286 // clicking on the left-most pixel will activate the back button.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 go_->SetBounds(location_bar_->x() + location_bar_->width(), child_y, 326 go_->SetBounds(location_bar_->x() + location_bar_->width(), child_y,
314 go_button_width, child_height); 327 go_button_width, child_height);
315 328
316 page_menu_->SetBounds(go_->x() + go_->width() + kMenuButtonOffset, child_y, 329 page_menu_->SetBounds(go_->x() + go_->width() + kMenuButtonOffset, child_y,
317 page_menu_width, child_height); 330 page_menu_width, child_height);
318 331
319 app_menu_->SetBounds(page_menu_->x() + page_menu_->width(), child_y, 332 app_menu_->SetBounds(page_menu_->x() + page_menu_->width(), child_y,
320 app_menu_width, child_height); 333 app_menu_width, child_height);
321 } 334 }
322 335
336 void BrowserToolbarView::Paint(ChromeCanvas* canvas) {
337 View::Paint(canvas);
338
339 if (IsDisplayModeNormal())
340 return;
341
342 // In maximized mode, we don't draw the endcaps on the location bar, because
343 // when they're flush against the edge of the screen they just look glitchy.
344 if (!browser_->window() || !browser_->window()->IsMaximized()) {
345 int top_spacing = PopupTopSpacing();
346 canvas->DrawBitmapInt(*kPopupBackgroundEdge, 0, top_spacing);
347 canvas->DrawBitmapInt(*kPopupBackgroundEdge,
348 width() - kPopupBackgroundEdge->width(), top_spacing);
349 }
350
351 // For glass, we need to draw a black line below the location bar to separate
352 // it from the content area. For non-glass, the NonClientView draws the
353 // toolbar background below the location bar for us.
354 if (win_util::ShouldUseVistaFrame())
355 canvas->FillRectInt(SK_ColorBLACK, 0, height() - 1, width(), 1);
356 }
357
323 void BrowserToolbarView::DidGainFocus() { 358 void BrowserToolbarView::DidGainFocus() {
324 // Check to see if MSAA focus should be restored to previously focused button, 359 // Check to see if MSAA focus should be restored to previously focused button,
325 // and if button is an enabled, visibled child of toolbar. 360 // and if button is an enabled, visibled child of toolbar.
326 if (!acc_focused_view() || 361 if (!acc_focused_view() ||
327 (acc_focused_view()->GetParent()->GetID() != VIEW_ID_TOOLBAR) || 362 (acc_focused_view()->GetParent()->GetID() != VIEW_ID_TOOLBAR) ||
328 !acc_focused_view()->IsEnabled() || 363 !acc_focused_view()->IsEnabled() ||
329 !acc_focused_view()->IsVisible()) { 364 !acc_focused_view()->IsVisible()) {
330 // Find first accessible child (-1 to start search at parent). 365 // Find first accessible child (-1 to start search at parent).
331 int first_acc_child = GetNextAccessibleViewIndex(-1, false); 366 int first_acc_child = GetNextAccessibleViewIndex(-1, false);
332 367
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 gfx::Size BrowserToolbarView::GetPreferredSize() { 487 gfx::Size BrowserToolbarView::GetPreferredSize() {
453 if (IsDisplayModeNormal()) { 488 if (IsDisplayModeNormal()) {
454 static SkBitmap normal_background; 489 static SkBitmap normal_background;
455 if (normal_background.isNull()) { 490 if (normal_background.isNull()) {
456 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 491 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
457 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); 492 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER);
458 } 493 }
459 return gfx::Size(0, normal_background.height()); 494 return gfx::Size(0, normal_background.height());
460 } 495 }
461 496
462 // With the non-Vista frame, we'll draw a client edge below the toolbar for 497 int vertical_spacing = PopupTopSpacing() + (win_util::ShouldUseVistaFrame() ?
463 // non-maximized popups. 498 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass);
464 // Note: We make sure to return the same value in the "no browser window" case 499 return gfx::Size(0, location_bar_->GetPreferredSize().height() +
465 // as the "not maximized" case, so that when a popup is opened at a particular 500 vertical_spacing);
466 // requested size, we'll report the same preferred size during the initial
467 // window size calculation (when there isn't yet a browser window) as when
468 // we're actually laying things out after setting up the browser window. This
469 // prevents the content area from being off by |kClientEdgeThickness| px.
470 int client_edge_height = win_util::ShouldUseVistaFrame() ||
471 (browser_->window() && browser_->window()->IsMaximized()) ?
472 0 : views::NonClientView::kClientEdgeThickness;
473 return gfx::Size(0,
474 location_bar_->GetPreferredSize().height() + client_edge_height);
475 } 501 }
476 502
477 void BrowserToolbarView::RunPageMenu(const CPoint& pt, HWND hwnd) { 503 void BrowserToolbarView::RunPageMenu(const CPoint& pt, HWND hwnd) {
478 Menu::AnchorPoint anchor = Menu::TOPRIGHT; 504 Menu::AnchorPoint anchor = Menu::TOPRIGHT;
479 if (UILayoutIsRightToLeft()) 505 if (UILayoutIsRightToLeft())
480 anchor = Menu::TOPLEFT; 506 anchor = Menu::TOPLEFT;
481 507
482 Menu menu(this, anchor, hwnd); 508 Menu menu(this, anchor, hwnd);
483 menu.AppendMenuItemWithLabel(IDC_CREATE_SHORTCUTS, 509 menu.AppendMenuItemWithLabel(IDC_CREATE_SHORTCUTS,
484 l10n_util::GetString(IDS_CREATE_SHORTCUTS)); 510 l10n_util::GetString(IDS_CREATE_SHORTCUTS));
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 break; 789 break;
764 } 790 }
765 if (button) 791 if (button)
766 button->SetEnabled(enabled); 792 button->SetEnabled(enabled);
767 } 793 }
768 794
769 void BrowserToolbarView::ButtonPressed(views::BaseButton* sender) { 795 void BrowserToolbarView::ButtonPressed(views::BaseButton* sender) {
770 browser_->ExecuteCommand(sender->GetTag()); 796 browser_->ExecuteCommand(sender->GetTag());
771 } 797 }
772 798
799 // static
800 int BrowserToolbarView::PopupTopSpacing() {
801 return win_util::ShouldUseVistaFrame() ? 0 : kPopupTopSpacingNonGlass;
802 }
803
773 void BrowserToolbarView::Observe(NotificationType type, 804 void BrowserToolbarView::Observe(NotificationType type,
774 const NotificationSource& source, 805 const NotificationSource& source,
775 const NotificationDetails& details) { 806 const NotificationDetails& details) {
776 if (type == NotificationType::PREF_CHANGED) { 807 if (type == NotificationType::PREF_CHANGED) {
777 std::wstring* pref_name = Details<std::wstring>(details).ptr(); 808 std::wstring* pref_name = Details<std::wstring>(details).ptr();
778 if (*pref_name == prefs::kShowHomeButton) { 809 if (*pref_name == prefs::kShowHomeButton) {
779 Layout(); 810 Layout();
780 SchedulePaint(); 811 SchedulePaint();
781 } 812 }
782 } 813 }
(...skipping 12 matching lines...) Expand all
795 *accel = views::Accelerator(L'C', false, true, false); 826 *accel = views::Accelerator(L'C', false, true, false);
796 return true; 827 return true;
797 case IDC_PASTE: 828 case IDC_PASTE:
798 *accel = views::Accelerator(L'V', false, true, false); 829 *accel = views::Accelerator(L'V', false, true, false);
799 return true; 830 return true;
800 } 831 }
801 // Else, we retrieve the accelerator information from the frame. 832 // Else, we retrieve the accelerator information from the frame.
802 return GetWidget()->GetAccelerator(id, accel); 833 return GetWidget()->GetAccelerator(id, accel);
803 } 834 }
804 835
OLDNEW
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698