| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/location_bar/keyword_hint_view.h" | 5 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | 13 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 14 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 14 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 16 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 17 #include "components/search_engines/template_url_service.h" | 17 #include "components/search_engines/template_url_service.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/gfx/color_utils.h" | 19 #include "ui/gfx/color_utils.h" |
| 20 #include "ui/keyboard/keyboard_util.h" | |
| 21 #include "ui/strings/grit/ui_strings.h" | 20 #include "ui/strings/grit/ui_strings.h" |
| 22 #include "ui/views/border.h" | 21 #include "ui/views/border.h" |
| 23 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
| 24 | 23 |
| 24 #if defined(USE_AURA) |
| 25 #include "ui/keyboard/keyboard_util.h" |
| 26 #endif |
| 27 |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 // This view looks somewhat like a keyboard key. | 30 // This view looks somewhat like a keyboard key. |
| 28 class KeyboardKeyView : public views::Label { | 31 class KeyboardKeyView : public views::Label { |
| 29 public: | 32 public: |
| 30 explicit KeyboardKeyView(const gfx::FontList& font_list); | 33 explicit KeyboardKeyView(const gfx::FontList& font_list); |
| 31 ~KeyboardKeyView() override; | 34 ~KeyboardKeyView() override; |
| 32 | 35 |
| 33 private: | 36 private: |
| 34 // views::Label: | 37 // views::Label: |
| 35 gfx::Size GetPreferredSize() const override; | 38 gfx::Size GetPreferredSize() const override; |
| 36 | 39 |
| 37 DISALLOW_COPY_AND_ASSIGN(KeyboardKeyView); | 40 DISALLOW_COPY_AND_ASSIGN(KeyboardKeyView); |
| 38 }; | 41 }; |
| 39 | 42 |
| 43 bool IsVirtualKeyboardVisible() { |
| 44 #if defined(USE_AURA) |
| 45 return keyboard::IsKeyboardVisible(); |
| 46 #else |
| 47 return false; |
| 48 #endif |
| 49 } |
| 50 |
| 40 KeyboardKeyView::KeyboardKeyView(const gfx::FontList& font_list) | 51 KeyboardKeyView::KeyboardKeyView(const gfx::FontList& font_list) |
| 41 : views::Label(base::string16(), {font_list}) { | 52 : views::Label(base::string16(), {font_list}) { |
| 42 SetBorder(views::CreateEmptyBorder( | 53 SetBorder(views::CreateEmptyBorder( |
| 43 gfx::Insets(LocationBarView::kBubbleVerticalPadding, 0))); | 54 gfx::Insets(LocationBarView::kBubbleVerticalPadding, 0))); |
| 44 } | 55 } |
| 45 | 56 |
| 46 KeyboardKeyView::~KeyboardKeyView() {} | 57 KeyboardKeyView::~KeyboardKeyView() {} |
| 47 | 58 |
| 48 gfx::Size KeyboardKeyView::GetPreferredSize() const { | 59 gfx::Size KeyboardKeyView::GetPreferredSize() const { |
| 49 gfx::Size size = views::Label::GetPreferredSize(); | 60 gfx::Size size = views::Label::GetPreferredSize(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 DCHECK(profile_); | 103 DCHECK(profile_); |
| 93 TemplateURLService* url_service = | 104 TemplateURLService* url_service = |
| 94 TemplateURLServiceFactory::GetForProfile(profile_); | 105 TemplateURLServiceFactory::GetForProfile(profile_); |
| 95 if (!url_service) | 106 if (!url_service) |
| 96 return; | 107 return; |
| 97 | 108 |
| 98 bool is_extension_keyword; | 109 bool is_extension_keyword; |
| 99 base::string16 short_name( | 110 base::string16 short_name( |
| 100 url_service->GetKeywordShortName(keyword, &is_extension_keyword)); | 111 url_service->GetKeywordShortName(keyword, &is_extension_keyword)); |
| 101 | 112 |
| 102 if (keyboard::IsKeyboardVisible()) { | 113 if (IsVirtualKeyboardVisible()) { |
| 103 int message_id = is_extension_keyword | 114 int message_id = is_extension_keyword |
| 104 ? IDS_OMNIBOX_EXTENSION_KEYWORD_HINT_TOUCH | 115 ? IDS_OMNIBOX_EXTENSION_KEYWORD_HINT_TOUCH |
| 105 : IDS_OMNIBOX_KEYWORD_HINT_TOUCH; | 116 : IDS_OMNIBOX_KEYWORD_HINT_TOUCH; |
| 106 chip_view_->SetText(l10n_util::GetStringFUTF16(message_id, short_name)); | 117 chip_view_->SetText(l10n_util::GetStringFUTF16(message_id, short_name)); |
| 107 | 118 |
| 108 leading_label_->SetText(base::string16()); | 119 leading_label_->SetText(base::string16()); |
| 109 trailing_label_->SetText(base::string16()); | 120 trailing_label_->SetText(base::string16()); |
| 110 } else { | 121 } else { |
| 111 chip_view_->SetText(l10n_util::GetStringUTF16(IDS_APP_TAB_KEY)); | 122 chip_view_->SetText(l10n_util::GetStringUTF16(IDS_APP_TAB_KEY)); |
| 112 | 123 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 168 |
| 158 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list, | 169 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list, |
| 159 SkColor text_color, | 170 SkColor text_color, |
| 160 SkColor background_color) { | 171 SkColor background_color) { |
| 161 views::Label* label = new views::Label(base::string16(), {font_list}); | 172 views::Label* label = new views::Label(base::string16(), {font_list}); |
| 162 label->SetEnabledColor(text_color); | 173 label->SetEnabledColor(text_color); |
| 163 label->SetBackgroundColor(background_color); | 174 label->SetBackgroundColor(background_color); |
| 164 AddChildView(label); | 175 AddChildView(label); |
| 165 return label; | 176 return label; |
| 166 } | 177 } |
| OLD | NEW |