| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/wrench_menu.h" | 5 #include "chrome/browser/ui/views/wrench_menu.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 string_id, type, index, background, string_id); | 275 string_id, type, index, background, string_id); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TextButton* CreateButtonWithAccName(int string_id, | 278 TextButton* CreateButtonWithAccName(int string_id, |
| 279 MenuButtonBackground::ButtonType type, | 279 MenuButtonBackground::ButtonType type, |
| 280 int index, | 280 int index, |
| 281 MenuButtonBackground** background, | 281 MenuButtonBackground** background, |
| 282 int acc_string_id) { | 282 int acc_string_id) { |
| 283 TextButton* button = | 283 TextButton* button = |
| 284 new TextButton(this, UTF16ToWide(l10n_util::GetStringUTF16(string_id))); | 284 new TextButton(this, UTF16ToWide(l10n_util::GetStringUTF16(string_id))); |
| 285 button->SetAccessibleName(UTF16ToWide( | 285 button->SetAccessibleName( |
| 286 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id))); | 286 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id)); |
| 287 button->SetFocusable(true); | 287 button->SetFocusable(true); |
| 288 button->set_request_focus_on_press(false); | 288 button->set_request_focus_on_press(false); |
| 289 button->set_tag(index); | 289 button->set_tag(index); |
| 290 button->SetEnabled(menu_model_->IsEnabledAt(index)); | 290 button->SetEnabled(menu_model_->IsEnabledAt(index)); |
| 291 button->set_prefix_type(TextButton::PREFIX_HIDE); | 291 button->set_prefix_type(TextButton::PREFIX_HIDE); |
| 292 MenuButtonBackground* bg = new MenuButtonBackground(type); | 292 MenuButtonBackground* bg = new MenuButtonBackground(type); |
| 293 button->set_background(bg); | 293 button->set_background(bg); |
| 294 button->SetEnabledColor(MenuConfig::instance().text_color); | 294 button->SetEnabledColor(MenuConfig::instance().text_color); |
| 295 if (background) | 295 if (background) |
| 296 *background = bg; | 296 *background = bg; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 IDR_FULLSCREEN_MENU_BUTTON)); | 423 IDR_FULLSCREEN_MENU_BUTTON)); |
| 424 fullscreen_button_->SetFocusable(true); | 424 fullscreen_button_->SetFocusable(true); |
| 425 fullscreen_button_->set_request_focus_on_press(false); | 425 fullscreen_button_->set_request_focus_on_press(false); |
| 426 fullscreen_button_->set_tag(fullscreen_index); | 426 fullscreen_button_->set_tag(fullscreen_index); |
| 427 fullscreen_button_->SetImageAlignment( | 427 fullscreen_button_->SetImageAlignment( |
| 428 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); | 428 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); |
| 429 fullscreen_button_->set_border(views::Border::CreateEmptyBorder( | 429 fullscreen_button_->set_border(views::Border::CreateEmptyBorder( |
| 430 0, kHorizontalPadding, 0, kHorizontalPadding)); | 430 0, kHorizontalPadding, 0, kHorizontalPadding)); |
| 431 fullscreen_button_->set_background( | 431 fullscreen_button_->set_background( |
| 432 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON)); | 432 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON)); |
| 433 fullscreen_button_->SetAccessibleName(UTF16ToWide( | 433 fullscreen_button_->SetAccessibleName( |
| 434 GetAccessibleNameForWrenchMenuItem( | 434 GetAccessibleNameForWrenchMenuItem( |
| 435 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN))); | 435 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); |
| 436 AddChildView(fullscreen_button_); | 436 AddChildView(fullscreen_button_); |
| 437 | 437 |
| 438 UpdateZoomControls(); | 438 UpdateZoomControls(); |
| 439 | 439 |
| 440 registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, | 440 registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, |
| 441 Source<Profile>(menu->browser_->profile())); | 441 Source<Profile>(menu->browser_->profile())); |
| 442 } | 442 } |
| 443 | 443 |
| 444 gfx::Size GetPreferredSize() { | 444 gfx::Size GetPreferredSize() { |
| 445 // The increment/decrement button are forced to the same width. | 445 // The increment/decrement button are forced to the same width. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 | 565 |
| 566 WrenchMenu::WrenchMenu(Browser* browser) | 566 WrenchMenu::WrenchMenu(Browser* browser) |
| 567 : browser_(browser), | 567 : browser_(browser), |
| 568 selected_menu_model_(NULL), | 568 selected_menu_model_(NULL), |
| 569 selected_index_(0) { | 569 selected_index_(0) { |
| 570 } | 570 } |
| 571 | 571 |
| 572 void WrenchMenu::Init(menus::MenuModel* model) { | 572 void WrenchMenu::Init(menus::MenuModel* model) { |
| 573 DCHECK(!root_.get()); | 573 DCHECK(!root_.get()); |
| 574 root_.reset(new MenuItemView(this)); | 574 root_.reset(new MenuItemView(this)); |
| 575 root_->SetAccessibleName( | 575 root_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); |
| 576 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_APP))); | |
| 577 root_->set_has_icons(true); // We have checks, radios and icons, set this | 576 root_->set_has_icons(true); // We have checks, radios and icons, set this |
| 578 // so we get the taller menu style. | 577 // so we get the taller menu style. |
| 579 int next_id = 1; | 578 int next_id = 1; |
| 580 PopulateMenu(root_.get(), model, &next_id); | 579 PopulateMenu(root_.get(), model, &next_id); |
| 581 } | 580 } |
| 582 | 581 |
| 583 void WrenchMenu::RunMenu(views::MenuButton* host) { | 582 void WrenchMenu::RunMenu(views::MenuButton* host) { |
| 584 // Up the ref count while the menu is displaying. This way if the window is | 583 // Up the ref count while the menu is displaying. This way if the window is |
| 585 // deleted while we're running we won't prematurely delete the menu. | 584 // deleted while we're running we won't prematurely delete the menu. |
| 586 // TODO(sky): fix this, the menu should really take ownership of the menu | 585 // TODO(sky): fix this, the menu should really take ownership of the menu |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 } | 704 } |
| 706 | 705 |
| 707 return menu_item; | 706 return menu_item; |
| 708 } | 707 } |
| 709 | 708 |
| 710 void WrenchMenu::CancelAndEvaluate(MenuModel* model, int index) { | 709 void WrenchMenu::CancelAndEvaluate(MenuModel* model, int index) { |
| 711 selected_menu_model_ = model; | 710 selected_menu_model_ = model; |
| 712 selected_index_ = index; | 711 selected_index_ = index; |
| 713 root_->Cancel(); | 712 root_->Cancel(); |
| 714 } | 713 } |
| OLD | NEW |