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/chromeos/dom_ui/menu_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/menu_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/menus/menu_model.h" | 9 #include "app/menus/menu_model.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "views/controls/menu/menu_config.h" | 36 #include "views/controls/menu/menu_config.h" |
37 #include "views/controls/menu/radio_button_image_gtk.h" | 37 #include "views/controls/menu/radio_button_image_gtk.h" |
38 #include "views/widget/widget_gtk.h" | 38 #include "views/widget/widget_gtk.h" |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // a fake resource id for not loading extra resource. | 42 // a fake resource id for not loading extra resource. |
43 const int kNoExtraResource = -1; | 43 const int kNoExtraResource = -1; |
44 | 44 |
45 // A utility function that generates css font property from gfx::Font. | 45 // A utility function that generates css font property from gfx::Font. |
46 // NOTE: Returns UTF-8. | 46 std::wstring GetFontShorthand(const gfx::Font* font) { |
47 std::string GetFontShorthand(const gfx::Font* font) { | 47 std::wstring out; |
48 std::string out; | |
49 if (font == NULL) { | 48 if (font == NULL) { |
50 font = &(views::MenuConfig::instance().font); | 49 font = &(views::MenuConfig::instance().font); |
51 } | 50 } |
52 if (font->GetStyle() & gfx::Font::BOLD) { | 51 if (font->GetStyle() & gfx::Font::BOLD) { |
53 out.append("bold "); | 52 out.append(L"bold "); |
54 } | 53 } |
55 if (font->GetStyle() & gfx::Font::ITALIC) { | 54 if (font->GetStyle() & gfx::Font::ITALIC) { |
56 out.append("italic "); | 55 out.append(L"italic "); |
57 } | 56 } |
58 if (font->GetStyle() & gfx::Font::UNDERLINED) { | 57 if (font->GetStyle() & gfx::Font::UNDERLINED) { |
59 out.append("underline "); | 58 out.append(L"underline "); |
60 } | 59 } |
61 | 60 |
62 // TODO(oshima): The font size from gfx::Font is too small when | 61 // TODO(oshima): The font size from gfx::Font is too small when |
63 // used in webkit. Figure out the reason. | 62 // used in webkit. Figure out the reason. |
64 out.append(base::IntToString(font->GetFontSize() + 4)); | 63 out.append(ASCIIToWide(base::IntToString(font->GetFontSize() + 4))); |
65 out.append("px/"); | 64 out.append(L"px/"); |
66 out.append(base::IntToString(std::max(kFavIconSize, font->GetHeight()))); | 65 out.append(ASCIIToWide(base::IntToString( |
67 out.append("px \""); | 66 std::max(kFavIconSize, font->GetHeight())))); |
68 out.append(UTF16ToUTF8(font->GetFontName())); | 67 out.append(L"px \""); |
69 out.append("\",sans-serif"); | 68 out.append(font->GetFontName()); |
| 69 out.append(L"\",sans-serif"); |
70 return out; | 70 return out; |
71 } | 71 } |
72 | 72 |
73 // Creates scroll button's up image when |up| is true or | 73 // Creates scroll button's up image when |up| is true or |
74 // down image if |up| is false. | 74 // down image if |up| is false. |
75 SkBitmap CreateMenuScrollArrowImage(bool up) { | 75 SkBitmap CreateMenuScrollArrowImage(bool up) { |
76 const views::MenuConfig& config = views::MenuConfig::instance(); | 76 const views::MenuConfig& config = views::MenuConfig::instance(); |
77 | 77 |
78 int height = config.scroll_arrow_height; | 78 int height = config.scroll_arrow_height; |
79 gfx::CanvasSkia canvas(height * 2, height, false); | 79 gfx::CanvasSkia canvas(height * 2, height, false); |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 string16 label16 = model->GetLabelAt(index); | 612 string16 label16 = model->GetLabelAt(index); |
613 DictionaryValue* item = new DictionaryValue(); | 613 DictionaryValue* item = new DictionaryValue(); |
614 | 614 |
615 item->SetString("type", type); | 615 item->SetString("type", type); |
616 item->SetString("label", label16); | 616 item->SetString("label", label16); |
617 item->SetBoolean("enabled", model->IsEnabledAt(index)); | 617 item->SetBoolean("enabled", model->IsEnabledAt(index)); |
618 item->SetBoolean("visible", model->IsVisibleAt(index)); | 618 item->SetBoolean("visible", model->IsVisibleAt(index)); |
619 item->SetBoolean("checked", model->IsItemCheckedAt(index)); | 619 item->SetBoolean("checked", model->IsItemCheckedAt(index)); |
620 item->SetInteger("command_id", model->GetCommandIdAt(index)); | 620 item->SetInteger("command_id", model->GetCommandIdAt(index)); |
621 item->SetString( | 621 item->SetString( |
622 "font", GetFontShorthand(model->GetLabelFontAt(index))); | 622 "font", WideToUTF16(GetFontShorthand(model->GetLabelFontAt(index)))); |
623 SkBitmap icon; | 623 SkBitmap icon; |
624 if (model->GetIconAt(index, &icon) && !icon.isNull() && !icon.empty()) { | 624 if (model->GetIconAt(index, &icon) && !icon.isNull() && !icon.empty()) { |
625 item->SetString("icon", dom_ui_util::GetImageDataUrl(icon)); | 625 item->SetString("icon", dom_ui_util::GetImageDataUrl(icon)); |
626 *max_icon_width = std::max(*max_icon_width, icon.width()); | 626 *max_icon_width = std::max(*max_icon_width, icon.width()); |
627 } | 627 } |
628 views::Accelerator menu_accelerator; | 628 views::Accelerator menu_accelerator; |
629 if (model->GetAcceleratorAt(index, &menu_accelerator)) { | 629 if (model->GetAcceleratorAt(index, &menu_accelerator)) { |
630 item->SetString("accel", menu_accelerator.GetShortcutText()); | 630 item->SetString("accel", menu_accelerator.GetShortcutText()); |
631 *has_accel = true; | 631 *has_accel = true; |
632 } | 632 } |
(...skipping 22 matching lines...) Expand all Loading... |
655 | 655 |
656 ChromeURLDataManager::DataSource* MenuUI::CreateDataSource() { | 656 ChromeURLDataManager::DataSource* MenuUI::CreateDataSource() { |
657 return CreateMenuUIHTMLSource(NULL, | 657 return CreateMenuUIHTMLSource(NULL, |
658 chrome::kChromeUIMenu, | 658 chrome::kChromeUIMenu, |
659 "Menu" /* class name */, | 659 "Menu" /* class name */, |
660 kNoExtraResource, | 660 kNoExtraResource, |
661 kNoExtraResource); | 661 kNoExtraResource); |
662 } | 662 } |
663 | 663 |
664 } // namespace chromeos | 664 } // namespace chromeos |
OLD | NEW |