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" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/app/chrome_dll_resource.h" | 13 #include "chrome/app/chrome_dll_resource.h" |
14 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
15 #include "chrome/browser/host_zoom_map.h" | 15 #include "chrome/browser/host_zoom_map.h" |
16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
17 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
18 #include "chrome/common/notification_observer.h" | 18 #include "chrome/common/notification_observer.h" |
19 #include "chrome/common/notification_registrar.h" | 19 #include "chrome/common/notification_registrar.h" |
20 #include "chrome/common/notification_source.h" | 20 #include "chrome/common/notification_source.h" |
21 #include "chrome/common/notification_type.h" | 21 #include "chrome/common/notification_type.h" |
22 #include "gfx/canvas.h" | 22 #include "gfx/canvas.h" |
23 #include "gfx/canvas_skia.h" | 23 #include "gfx/canvas_skia.h" |
24 #include "gfx/skia_util.h" | 24 #include "gfx/skia_util.h" |
| 25 #include "grit/chromium_strings.h" |
25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
26 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
27 #include "third_party/skia/include/core/SkPaint.h" | 28 #include "third_party/skia/include/core/SkPaint.h" |
28 #include "views/background.h" | 29 #include "views/background.h" |
29 #include "views/controls/button/image_button.h" | 30 #include "views/controls/button/image_button.h" |
30 #include "views/controls/button/menu_button.h" | 31 #include "views/controls/button/menu_button.h" |
31 #include "views/controls/button/text_button.h" | 32 #include "views/controls/button/text_button.h" |
32 #include "views/controls/label.h" | 33 #include "views/controls/label.h" |
33 #include "views/controls/menu/menu_config.h" | 34 #include "views/controls/menu/menu_config.h" |
34 #include "views/controls/menu/menu_item_view.h" | 35 #include "views/controls/menu/menu_item_view.h" |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 decrement_button_->SetEnabled(enable_decrement); | 471 decrement_button_->SetEnabled(enable_decrement); |
471 zoom_label_->SetText(l10n_util::GetStringF( | 472 zoom_label_->SetText(l10n_util::GetStringF( |
472 IDS_ZOOM_PERCENT, | 473 IDS_ZOOM_PERCENT, |
473 UTF8ToWide(base::IntToString(zoom_percent)))); | 474 UTF8ToWide(base::IntToString(zoom_percent)))); |
474 // If both increment and decrement are disabled, then we disable the zoom | 475 // If both increment and decrement are disabled, then we disable the zoom |
475 // label too. | 476 // label too. |
476 zoom_label_->SetEnabled(enable_increment || enable_decrement); | 477 zoom_label_->SetEnabled(enable_increment || enable_decrement); |
477 } | 478 } |
478 | 479 |
479 double GetZoom(bool* enable_increment, bool* enable_decrement) { | 480 double GetZoom(bool* enable_increment, bool* enable_decrement) { |
480 // TODO: move this somewhere it can be shared. | 481 // TODO(sky): move this somewhere it can be shared. |
481 TabContents* selected_tab = menu_->browser_->GetSelectedTabContents(); | 482 TabContents* selected_tab = menu_->browser_->GetSelectedTabContents(); |
482 *enable_decrement = *enable_increment = false; | 483 *enable_decrement = *enable_increment = false; |
483 if (!selected_tab) | 484 if (!selected_tab) |
484 return 1; | 485 return 1; |
485 | 486 |
486 HostZoomMap* zoom_map = selected_tab->profile()->GetHostZoomMap(); | 487 HostZoomMap* zoom_map = selected_tab->profile()->GetHostZoomMap(); |
487 if (!zoom_map) | 488 if (!zoom_map) |
488 return 1; | 489 return 1; |
489 | 490 |
490 int zoom_level = zoom_map->GetZoomLevel(selected_tab->GetURL()); | 491 int zoom_level = zoom_map->GetZoomLevel(selected_tab->GetURL()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 selected_menu_model_(NULL), | 551 selected_menu_model_(NULL), |
551 selected_index_(0) { | 552 selected_index_(0) { |
552 } | 553 } |
553 | 554 |
554 WrenchMenu::~WrenchMenu() { | 555 WrenchMenu::~WrenchMenu() { |
555 } | 556 } |
556 | 557 |
557 void WrenchMenu::Init(menus::MenuModel* model) { | 558 void WrenchMenu::Init(menus::MenuModel* model) { |
558 DCHECK(!root_.get()); | 559 DCHECK(!root_.get()); |
559 root_.reset(new MenuItemView(this)); | 560 root_.reset(new MenuItemView(this)); |
| 561 root_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); |
560 root_->set_has_icons(true); // We have checks, radios and icons, set this | 562 root_->set_has_icons(true); // We have checks, radios and icons, set this |
561 // so we get the taller menu style. | 563 // so we get the taller menu style. |
562 int next_id = 1; | 564 int next_id = 1; |
563 PopulateMenu(root_.get(), model, &next_id); | 565 PopulateMenu(root_.get(), model, &next_id); |
564 } | 566 } |
565 | 567 |
566 void WrenchMenu::RunMenu(views::MenuButton* host) { | 568 void WrenchMenu::RunMenu(views::MenuButton* host) { |
567 gfx::Point screen_loc; | 569 gfx::Point screen_loc; |
568 views::View::ConvertPointToScreen(host, &screen_loc); | 570 views::View::ConvertPointToScreen(host, &screen_loc); |
569 gfx::Rect bounds(screen_loc, host->size()); | 571 gfx::Rect bounds(screen_loc, host->size()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 } | 707 } |
706 | 708 |
707 return menu_item; | 709 return menu_item; |
708 } | 710 } |
709 | 711 |
710 void WrenchMenu::CancelAndEvaluate(MenuModel* model, int index) { | 712 void WrenchMenu::CancelAndEvaluate(MenuModel* model, int index) { |
711 selected_menu_model_ = model; | 713 selected_menu_model_ = model; |
712 selected_index_ = index; | 714 selected_index_ = index; |
713 root_->Cancel(); | 715 root_->Cancel(); |
714 } | 716 } |
OLD | NEW |