| 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/wrench_menu.h" | 5 #include "chrome/browser/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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 urgent); | 239 urgent); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 private: | 243 private: |
| 244 DISALLOW_COPY_AND_ASSIGN(ScheduleAllView); | 244 DISALLOW_COPY_AND_ASSIGN(ScheduleAllView); |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 std::wstring GetAccessibleNameForWrenchMenuItem( | 247 std::wstring GetAccessibleNameForWrenchMenuItem( |
| 248 MenuModel* model, int item_index, int accessible_string_id) { | 248 MenuModel* model, int item_index, int accessible_string_id) { |
| 249 std::wstring accessible_name = l10n_util::GetString(accessible_string_id); | 249 std::wstring accessible_name = |
| 250 UTF16ToWide(l10n_util::GetStringUTF16(accessible_string_id)); |
| 250 std::wstring accelerator_text; | 251 std::wstring accelerator_text; |
| 251 | 252 |
| 252 menus::Accelerator menu_accelerator; | 253 menus::Accelerator menu_accelerator; |
| 253 if (model->GetAcceleratorAt(item_index, &menu_accelerator)) { | 254 if (model->GetAcceleratorAt(item_index, &menu_accelerator)) { |
| 254 accelerator_text = | 255 accelerator_text = |
| 255 views::Accelerator(menu_accelerator.GetKeyCode(), | 256 views::Accelerator(menu_accelerator.GetKeyCode(), |
| 256 menu_accelerator.modifiers()).GetShortcutText(); | 257 menu_accelerator.modifiers()).GetShortcutText(); |
| 257 } | 258 } |
| 258 | 259 |
| 259 return MenuItemView::GetAccessibleNameForMenuItem( | 260 return MenuItemView::GetAccessibleNameForMenuItem( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 273 return CreateButtonWithAccName( | 274 return CreateButtonWithAccName( |
| 274 string_id, type, index, background, string_id); | 275 string_id, type, index, background, string_id); |
| 275 } | 276 } |
| 276 | 277 |
| 277 TextButton* CreateButtonWithAccName(int string_id, | 278 TextButton* CreateButtonWithAccName(int string_id, |
| 278 MenuButtonBackground::ButtonType type, | 279 MenuButtonBackground::ButtonType type, |
| 279 int index, | 280 int index, |
| 280 MenuButtonBackground** background, | 281 MenuButtonBackground** background, |
| 281 int acc_string_id) { | 282 int acc_string_id) { |
| 282 TextButton* button = | 283 TextButton* button = |
| 283 new TextButton(this, l10n_util::GetString(string_id)); | 284 new TextButton(this, UTF16ToWide(l10n_util::GetStringUTF16(string_id))); |
| 284 button->SetAccessibleName( | 285 button->SetAccessibleName( |
| 285 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id)); | 286 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id)); |
| 286 button->SetFocusable(true); | 287 button->SetFocusable(true); |
| 287 button->set_request_focus_on_press(false); | 288 button->set_request_focus_on_press(false); |
| 288 button->set_tag(index); | 289 button->set_tag(index); |
| 289 button->SetEnabled(menu_model_->IsEnabledAt(index)); | 290 button->SetEnabled(menu_model_->IsEnabledAt(index)); |
| 290 button->set_prefix_type(TextButton::PREFIX_HIDE); | 291 button->set_prefix_type(TextButton::PREFIX_HIDE); |
| 291 MenuButtonBackground* bg = new MenuButtonBackground(type); | 292 MenuButtonBackground* bg = new MenuButtonBackground(type); |
| 292 button->set_background(bg); | 293 button->set_background(bg); |
| 293 button->SetEnabledColor(MenuConfig::instance().text_color); | 294 button->SetEnabledColor(MenuConfig::instance().text_color); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 fullscreen_index_(fullscreen_index), | 391 fullscreen_index_(fullscreen_index), |
| 391 increment_button_(NULL), | 392 increment_button_(NULL), |
| 392 zoom_label_(NULL), | 393 zoom_label_(NULL), |
| 393 decrement_button_(NULL), | 394 decrement_button_(NULL), |
| 394 fullscreen_button_(NULL), | 395 fullscreen_button_(NULL), |
| 395 zoom_label_width_(0) { | 396 zoom_label_width_(0) { |
| 396 decrement_button_ = CreateButtonWithAccName( | 397 decrement_button_ = CreateButtonWithAccName( |
| 397 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, | 398 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, |
| 398 NULL, IDS_ACCNAME_ZOOM_MINUS2); | 399 NULL, IDS_ACCNAME_ZOOM_MINUS2); |
| 399 | 400 |
| 400 zoom_label_ = new Label(l10n_util::GetStringF(IDS_ZOOM_PERCENT, L"100")); | 401 zoom_label_ = new Label( |
| 402 UTF16ToWide(l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100))); |
| 401 zoom_label_->SetColor(MenuConfig::instance().text_color); | 403 zoom_label_->SetColor(MenuConfig::instance().text_color); |
| 402 zoom_label_->SetHorizontalAlignment(Label::ALIGN_RIGHT); | 404 zoom_label_->SetHorizontalAlignment(Label::ALIGN_RIGHT); |
| 403 MenuButtonBackground* center_bg = | 405 MenuButtonBackground* center_bg = |
| 404 new MenuButtonBackground(MenuButtonBackground::CENTER_BUTTON); | 406 new MenuButtonBackground(MenuButtonBackground::CENTER_BUTTON); |
| 405 zoom_label_->set_background(center_bg); | 407 zoom_label_->set_background(center_bg); |
| 406 zoom_label_->set_border(new MenuButtonBorder()); | 408 zoom_label_->set_border(new MenuButtonBorder()); |
| 407 zoom_label_->SetFont(MenuConfig::instance().font); | 409 zoom_label_->SetFont(MenuConfig::instance().font); |
| 408 AddChildView(zoom_label_); | 410 AddChildView(zoom_label_); |
| 409 zoom_label_width_ = MaxWidthForZoomLabel(); | 411 zoom_label_width_ = MaxWidthForZoomLabel(); |
| 410 | 412 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 private: | 497 private: |
| 496 void UpdateZoomControls() { | 498 void UpdateZoomControls() { |
| 497 bool enable_increment = false; | 499 bool enable_increment = false; |
| 498 bool enable_decrement = false; | 500 bool enable_decrement = false; |
| 499 TabContents* selected_tab = menu_->browser_->GetSelectedTabContents(); | 501 TabContents* selected_tab = menu_->browser_->GetSelectedTabContents(); |
| 500 int zoom = 100; | 502 int zoom = 100; |
| 501 if (selected_tab) | 503 if (selected_tab) |
| 502 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement); | 504 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement); |
| 503 increment_button_->SetEnabled(enable_increment); | 505 increment_button_->SetEnabled(enable_increment); |
| 504 decrement_button_->SetEnabled(enable_decrement); | 506 decrement_button_->SetEnabled(enable_decrement); |
| 505 zoom_label_->SetText(l10n_util::GetStringF( | 507 zoom_label_->SetText(UTF16ToWide(l10n_util::GetStringFUTF16Int( |
| 506 IDS_ZOOM_PERCENT, | 508 IDS_ZOOM_PERCENT, |
| 507 UTF8ToWide(base::IntToString(zoom)))); | 509 zoom))); |
| 508 | 510 |
| 509 zoom_label_width_ = MaxWidthForZoomLabel(); | 511 zoom_label_width_ = MaxWidthForZoomLabel(); |
| 510 } | 512 } |
| 511 | 513 |
| 512 // Calculates the max width the zoom string can be. | 514 // Calculates the max width the zoom string can be. |
| 513 int MaxWidthForZoomLabel() { | 515 int MaxWidthForZoomLabel() { |
| 514 gfx::Font font = zoom_label_->font(); | 516 gfx::Font font = zoom_label_->font(); |
| 515 gfx::Insets insets; | 517 gfx::Insets insets; |
| 516 if (zoom_label_->border()) | 518 if (zoom_label_->border()) |
| 517 zoom_label_->border()->GetInsets(&insets); | 519 zoom_label_->border()->GetInsets(&insets); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 565 |
| 564 WrenchMenu::WrenchMenu(Browser* browser) | 566 WrenchMenu::WrenchMenu(Browser* browser) |
| 565 : browser_(browser), | 567 : browser_(browser), |
| 566 selected_menu_model_(NULL), | 568 selected_menu_model_(NULL), |
| 567 selected_index_(0) { | 569 selected_index_(0) { |
| 568 } | 570 } |
| 569 | 571 |
| 570 void WrenchMenu::Init(menus::MenuModel* model) { | 572 void WrenchMenu::Init(menus::MenuModel* model) { |
| 571 DCHECK(!root_.get()); | 573 DCHECK(!root_.get()); |
| 572 root_.reset(new MenuItemView(this)); | 574 root_.reset(new MenuItemView(this)); |
| 573 root_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); | 575 root_->SetAccessibleName( |
| 576 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_APP))); |
| 574 root_->set_has_icons(true); // We have checks, radios and icons, set this | 577 root_->set_has_icons(true); // We have checks, radios and icons, set this |
| 575 // so we get the taller menu style. | 578 // so we get the taller menu style. |
| 576 int next_id = 1; | 579 int next_id = 1; |
| 577 PopulateMenu(root_.get(), model, &next_id); | 580 PopulateMenu(root_.get(), model, &next_id); |
| 578 } | 581 } |
| 579 | 582 |
| 580 void WrenchMenu::RunMenu(views::MenuButton* host) { | 583 void WrenchMenu::RunMenu(views::MenuButton* host) { |
| 581 // Up the ref count while the menu is displaying. This way if the window is | 584 // Up the ref count while the menu is displaying. This way if the window is |
| 582 // deleted while we're running we won't prematurely delete the menu. | 585 // deleted while we're running we won't prematurely delete the menu. |
| 583 // TODO(sky): fix this, the menu should really take ownership of the menu | 586 // TODO(sky): fix this, the menu should really take ownership of the menu |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 AppendMenuItem(parent, model, index, model->GetTypeAt(index), next_id); | 659 AppendMenuItem(parent, model, index, model->GetTypeAt(index), next_id); |
| 657 | 660 |
| 658 if (model->GetTypeAt(index) == MenuModel::TYPE_SUBMENU) | 661 if (model->GetTypeAt(index) == MenuModel::TYPE_SUBMENU) |
| 659 PopulateMenu(item, model->GetSubmenuModelAt(index), next_id); | 662 PopulateMenu(item, model->GetSubmenuModelAt(index), next_id); |
| 660 | 663 |
| 661 if (model->GetCommandIdAt(index) == IDC_CUT) { | 664 if (model->GetCommandIdAt(index) == IDC_CUT) { |
| 662 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(index)); | 665 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(index)); |
| 663 DCHECK_LT(i + 2, max); | 666 DCHECK_LT(i + 2, max); |
| 664 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(index + 1)); | 667 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(index + 1)); |
| 665 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(index + 2)); | 668 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(index + 2)); |
| 666 item->SetTitle(l10n_util::GetString(IDS_EDIT2)); | 669 item->SetTitle(UTF16ToWide(l10n_util::GetStringUTF16(IDS_EDIT2))); |
| 667 item->AddChildView( | 670 item->AddChildView( |
| 668 new CutCopyPasteView(this, model, index, index + 1, index + 2)); | 671 new CutCopyPasteView(this, model, index, index + 1, index + 2)); |
| 669 i += 2; | 672 i += 2; |
| 670 } else if (model->GetCommandIdAt(index) == IDC_ZOOM_MINUS) { | 673 } else if (model->GetCommandIdAt(index) == IDC_ZOOM_MINUS) { |
| 671 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(index)); | 674 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(index)); |
| 672 DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(index + 1)); | 675 DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(index + 1)); |
| 673 DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(index + 2)); | 676 DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(index + 2)); |
| 674 item->SetTitle(l10n_util::GetString(IDS_ZOOM_MENU2)); | 677 item->SetTitle(UTF16ToWide(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2))); |
| 675 item->AddChildView( | 678 item->AddChildView( |
| 676 new ZoomView(this, model, index, index + 1, index + 2)); | 679 new ZoomView(this, model, index, index + 1, index + 2)); |
| 677 i += 2; | 680 i += 2; |
| 678 } | 681 } |
| 679 } | 682 } |
| 680 } | 683 } |
| 681 | 684 |
| 682 MenuItemView* WrenchMenu::AppendMenuItem(MenuItemView* parent, | 685 MenuItemView* WrenchMenu::AppendMenuItem(MenuItemView* parent, |
| 683 MenuModel* model, | 686 MenuModel* model, |
| 684 int index, | 687 int index, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 701 } | 704 } |
| 702 | 705 |
| 703 return menu_item; | 706 return menu_item; |
| 704 } | 707 } |
| 705 | 708 |
| 706 void WrenchMenu::CancelAndEvaluate(MenuModel* model, int index) { | 709 void WrenchMenu::CancelAndEvaluate(MenuModel* model, int index) { |
| 707 selected_menu_model_ = model; | 710 selected_menu_model_ = model; |
| 708 selected_index_ = index; | 711 selected_index_ = index; |
| 709 root_->Cancel(); | 712 root_->Cancel(); |
| 710 } | 713 } |
| OLD | NEW |