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 24 matching lines...) Expand all Loading... | |
35 #include "views/accelerator.h" | 35 #include "views/accelerator.h" |
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. |
evanm
2011/01/11 21:56:47
May wanna tag this as returning UTF-8, since we do
Avi (use Gerrit)
2011/01/11 22:15:28
Good point.
| |
46 std::wstring GetFontShorthand(const gfx::Font* font) { | 46 std::string GetFontShorthand(const gfx::Font* font) { |
47 std::wstring out; | 47 std::string out; |
48 if (font == NULL) { | 48 if (font == NULL) { |
49 font = &(views::MenuConfig::instance().font); | 49 font = &(views::MenuConfig::instance().font); |
50 } | 50 } |
51 if (font->GetStyle() & gfx::Font::BOLD) { | 51 if (font->GetStyle() & gfx::Font::BOLD) { |
52 out.append(L"bold "); | 52 out.append("bold "); |
53 } | 53 } |
54 if (font->GetStyle() & gfx::Font::ITALIC) { | 54 if (font->GetStyle() & gfx::Font::ITALIC) { |
55 out.append(L"italic "); | 55 out.append("italic "); |
56 } | 56 } |
57 if (font->GetStyle() & gfx::Font::UNDERLINED) { | 57 if (font->GetStyle() & gfx::Font::UNDERLINED) { |
58 out.append(L"underline "); | 58 out.append("underline "); |
59 } | 59 } |
60 | 60 |
61 // 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 |
62 // used in webkit. Figure out the reason. | 62 // used in webkit. Figure out the reason. |
63 out.append(ASCIIToWide(base::IntToString(font->GetFontSize() + 4))); | 63 out.append(base::IntToString(font->GetFontSize() + 4)); |
64 out.append(L"px/"); | 64 out.append("px/"); |
65 out.append(ASCIIToWide(base::IntToString( | 65 out.append(base::IntToString(std::max(kFavIconSize, font->GetHeight()))); |
66 std::max(kFavIconSize, font->GetHeight())))); | 66 out.append("px \""); |
67 out.append(L"px \""); | 67 out.append(UTF16ToUTF8(font->GetFontName())); |
68 out.append(font->GetFontName()); | 68 out.append("\",sans-serif"); |
69 out.append(L"\",sans-serif"); | |
70 return out; | 69 return out; |
71 } | 70 } |
72 | 71 |
73 // Creates scroll button's up image when |up| is true or | 72 // Creates scroll button's up image when |up| is true or |
74 // down image if |up| is false. | 73 // down image if |up| is false. |
75 SkBitmap CreateMenuScrollArrowImage(bool up) { | 74 SkBitmap CreateMenuScrollArrowImage(bool up) { |
76 const views::MenuConfig& config = views::MenuConfig::instance(); | 75 const views::MenuConfig& config = views::MenuConfig::instance(); |
77 | 76 |
78 int height = config.scroll_arrow_height; | 77 int height = config.scroll_arrow_height; |
79 gfx::CanvasSkia canvas(height * 2, height, false); | 78 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); | 611 string16 label16 = model->GetLabelAt(index); |
613 DictionaryValue* item = new DictionaryValue(); | 612 DictionaryValue* item = new DictionaryValue(); |
614 | 613 |
615 item->SetString("type", type); | 614 item->SetString("type", type); |
616 item->SetString("label", label16); | 615 item->SetString("label", label16); |
617 item->SetBoolean("enabled", model->IsEnabledAt(index)); | 616 item->SetBoolean("enabled", model->IsEnabledAt(index)); |
618 item->SetBoolean("visible", model->IsVisibleAt(index)); | 617 item->SetBoolean("visible", model->IsVisibleAt(index)); |
619 item->SetBoolean("checked", model->IsItemCheckedAt(index)); | 618 item->SetBoolean("checked", model->IsItemCheckedAt(index)); |
620 item->SetInteger("command_id", model->GetCommandIdAt(index)); | 619 item->SetInteger("command_id", model->GetCommandIdAt(index)); |
621 item->SetString( | 620 item->SetString( |
622 "font", WideToUTF16(GetFontShorthand(model->GetLabelFontAt(index)))); | 621 "font", GetFontShorthand(model->GetLabelFontAt(index))); |
623 SkBitmap icon; | 622 SkBitmap icon; |
624 if (model->GetIconAt(index, &icon) && !icon.isNull() && !icon.empty()) { | 623 if (model->GetIconAt(index, &icon) && !icon.isNull() && !icon.empty()) { |
625 item->SetString("icon", dom_ui_util::GetImageDataUrl(icon)); | 624 item->SetString("icon", dom_ui_util::GetImageDataUrl(icon)); |
626 *max_icon_width = std::max(*max_icon_width, icon.width()); | 625 *max_icon_width = std::max(*max_icon_width, icon.width()); |
627 } | 626 } |
628 views::Accelerator menu_accelerator; | 627 views::Accelerator menu_accelerator; |
629 if (model->GetAcceleratorAt(index, &menu_accelerator)) { | 628 if (model->GetAcceleratorAt(index, &menu_accelerator)) { |
630 item->SetString("accel", menu_accelerator.GetShortcutText()); | 629 item->SetString("accel", menu_accelerator.GetShortcutText()); |
631 *has_accel = true; | 630 *has_accel = true; |
632 } | 631 } |
(...skipping 22 matching lines...) Expand all Loading... | |
655 | 654 |
656 ChromeURLDataManager::DataSource* MenuUI::CreateDataSource() { | 655 ChromeURLDataManager::DataSource* MenuUI::CreateDataSource() { |
657 return CreateMenuUIHTMLSource(NULL, | 656 return CreateMenuUIHTMLSource(NULL, |
658 chrome::kChromeUIMenu, | 657 chrome::kChromeUIMenu, |
659 "Menu" /* class name */, | 658 "Menu" /* class name */, |
660 kNoExtraResource, | 659 kNoExtraResource, |
661 kNoExtraResource); | 660 kNoExtraResource); |
662 } | 661 } |
663 | 662 |
664 } // namespace chromeos | 663 } // namespace chromeos |
OLD | NEW |