OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/ime/infolist_window.h" | 5 #include "ash/ime/infolist_window.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ime/candidate_window_constants.h" | 10 #include "ash/ime/candidate_window_constants.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "grit/ash_strings.h" | 12 #include "grit/ash_strings.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/gfx/color_utils.h" | 14 #include "ui/gfx/color_utils.h" |
15 #include "ui/gfx/font.h" | |
16 #include "ui/native_theme/native_theme.h" | 15 #include "ui/native_theme/native_theme.h" |
17 #include "ui/views/background.h" | 16 #include "ui/views/background.h" |
18 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
19 #include "ui/views/bubble/bubble_border.h" | 18 #include "ui/views/bubble/bubble_border.h" |
20 #include "ui/views/bubble/bubble_frame_view.h" | 19 #include "ui/views/bubble/bubble_frame_view.h" |
21 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
22 #include "ui/views/corewm/window_animations.h" | 21 #include "ui/views/corewm/window_animations.h" |
23 #include "ui/views/layout/box_layout.h" | 22 #include "ui/views/layout/box_layout.h" |
24 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
25 | 24 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 // window without the gap. | 79 // window without the gap. |
81 return gfx::Insets(); | 80 return gfx::Insets(); |
82 } | 81 } |
83 | 82 |
84 } // namespace | 83 } // namespace |
85 | 84 |
86 // InfolistRow renderes a row of a infolist. | 85 // InfolistRow renderes a row of a infolist. |
87 class InfolistEntryView : public views::View { | 86 class InfolistEntryView : public views::View { |
88 public: | 87 public: |
89 InfolistEntryView(const ui::InfolistEntry& entry, | 88 InfolistEntryView(const ui::InfolistEntry& entry, |
90 const gfx::FontList& title_font, | 89 const gfx::FontList& title_font_list, |
91 const gfx::FontList& description_font); | 90 const gfx::FontList& description_font_list); |
92 virtual ~InfolistEntryView(); | 91 virtual ~InfolistEntryView(); |
93 | 92 |
94 void SetEntry(const ui::InfolistEntry& entry); | 93 void SetEntry(const ui::InfolistEntry& entry); |
95 | 94 |
96 private: | 95 private: |
97 // views::View implementation. | 96 // views::View implementation. |
98 virtual gfx::Size GetPreferredSize() OVERRIDE; | 97 virtual gfx::Size GetPreferredSize() OVERRIDE; |
99 | 98 |
100 void UpdateBackground(); | 99 void UpdateBackground(); |
101 | 100 |
102 ui::InfolistEntry entry_; | 101 ui::InfolistEntry entry_; |
103 | 102 |
104 // The title label. Owned by views hierarchy. | 103 // The title label. Owned by views hierarchy. |
105 views::Label* title_label_; | 104 views::Label* title_label_; |
106 | 105 |
107 // The description label. Owned by views hierarchy. | 106 // The description label. Owned by views hierarchy. |
108 views::Label* description_label_; | 107 views::Label* description_label_; |
109 | 108 |
110 DISALLOW_COPY_AND_ASSIGN(InfolistEntryView); | 109 DISALLOW_COPY_AND_ASSIGN(InfolistEntryView); |
111 }; | 110 }; |
112 | 111 |
113 InfolistEntryView::InfolistEntryView(const ui::InfolistEntry& entry, | 112 InfolistEntryView::InfolistEntryView(const ui::InfolistEntry& entry, |
114 const gfx::FontList& title_font, | 113 const gfx::FontList& title_font_list, |
115 const gfx::FontList& description_font) | 114 const gfx::FontList& description_font_list) |
116 : entry_(entry) { | 115 : entry_(entry) { |
117 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 116 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
118 | 117 |
119 title_label_ = new views::Label(entry.title); | 118 title_label_ = new views::Label(entry.title, title_font_list); |
120 title_label_->SetPosition(gfx::Point(0, 0)); | 119 title_label_->SetPosition(gfx::Point(0, 0)); |
121 title_label_->SetFontList(title_font); | |
122 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 120 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
123 title_label_->set_border( | 121 title_label_->set_border( |
124 views::Border::CreateEmptyBorder(4, 7, 2, 4)); | 122 views::Border::CreateEmptyBorder(4, 7, 2, 4)); |
125 | 123 |
126 description_label_ = new views::Label(entry.body); | 124 description_label_ = new views::Label(entry.body, description_font_list); |
127 description_label_->SetPosition(gfx::Point(0, 0)); | 125 description_label_->SetPosition(gfx::Point(0, 0)); |
128 description_label_->SetFontList(description_font); | |
129 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 126 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
130 description_label_->SetMultiLine(true); | 127 description_label_->SetMultiLine(true); |
131 description_label_->SizeToFit(kInfolistEntryWidth); | 128 description_label_->SizeToFit(kInfolistEntryWidth); |
132 description_label_->set_border( | 129 description_label_->set_border( |
133 views::Border::CreateEmptyBorder(2, 17, 4, 4)); | 130 views::Border::CreateEmptyBorder(2, 17, 4, 4)); |
134 AddChildView(title_label_); | 131 AddChildView(title_label_); |
135 AddChildView(description_label_); | 132 AddChildView(description_label_); |
136 UpdateBackground(); | 133 UpdateBackground(); |
137 } | 134 } |
138 | 135 |
(...skipping 27 matching lines...) Expand all Loading... | |
166 } | 163 } |
167 SchedulePaint(); | 164 SchedulePaint(); |
168 } | 165 } |
169 | 166 |
170 /////////////////////////////////////////////////////////////////////////////// | 167 /////////////////////////////////////////////////////////////////////////////// |
171 // InfolistWindow | 168 // InfolistWindow |
172 | 169 |
173 InfolistWindow::InfolistWindow(views::View* candidate_window, | 170 InfolistWindow::InfolistWindow(views::View* candidate_window, |
174 const std::vector<ui::InfolistEntry>& entries) | 171 const std::vector<ui::InfolistEntry>& entries) |
175 : views::BubbleDelegateView(candidate_window, views::BubbleBorder::NONE), | 172 : views::BubbleDelegateView(candidate_window, views::BubbleBorder::NONE), |
176 title_font_(gfx::Font(kJapaneseFontName, kFontSizeDelta + 15)), | 173 title_font_list_(gfx::Font(kJapaneseFontName, kFontSizeDelta + 15)), |
Alexei Svitkine (slow)
2014/01/23 18:47:54
I know your code isn't changing this, but I find t
Yuki
2014/01/24 10:23:20
Some people type Japanese text while using English
| |
177 description_font_(gfx::Font(kJapaneseFontName, kFontSizeDelta + 11)) { | 174 description_font_list_(gfx::Font(kJapaneseFontName, |
175 kFontSizeDelta + 11)) { | |
178 set_move_with_anchor(true); | 176 set_move_with_anchor(true); |
179 set_margins(gfx::Insets()); | 177 set_margins(gfx::Insets()); |
180 | 178 |
181 set_background( | 179 set_background( |
182 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 180 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
183 ui::NativeTheme::kColorId_WindowBackground))); | 181 ui::NativeTheme::kColorId_WindowBackground))); |
184 set_border( | 182 set_border( |
185 views::Border::CreateSolidBorder(1, GetNativeTheme()->GetSystemColor( | 183 views::Border::CreateSolidBorder(1, GetNativeTheme()->GetSystemColor( |
186 ui::NativeTheme::kColorId_MenuBorderColor))); | 184 ui::NativeTheme::kColorId_MenuBorderColor))); |
187 | 185 |
188 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 186 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
189 | 187 |
190 views::Label* caption_label = new views::Label( | 188 views::Label* caption_label = new views::Label( |
191 l10n_util::GetStringUTF16(IDS_ASH_IME_INFOLIST_WINDOW_TITLE)); | 189 l10n_util::GetStringUTF16(IDS_ASH_IME_INFOLIST_WINDOW_TITLE)); |
192 caption_label->SetFontList( | |
193 caption_label->font_list().DeriveFontList(kFontSizeDelta - 2)); | |
194 caption_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 190 caption_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
195 caption_label->SetEnabledColor(GetNativeTheme()->GetSystemColor( | 191 caption_label->SetEnabledColor(GetNativeTheme()->GetSystemColor( |
196 ui::NativeTheme::kColorId_LabelEnabledColor)); | 192 ui::NativeTheme::kColorId_LabelEnabledColor)); |
197 caption_label->set_border(views::Border::CreateEmptyBorder(2, 2, 2, 2)); | 193 caption_label->set_border(views::Border::CreateEmptyBorder(2, 2, 2, 2)); |
198 caption_label->set_background(views::Background::CreateSolidBackground( | 194 caption_label->set_background(views::Background::CreateSolidBackground( |
199 color_utils::AlphaBlend(SK_ColorBLACK, | 195 color_utils::AlphaBlend(SK_ColorBLACK, |
200 GetNativeTheme()->GetSystemColor( | 196 GetNativeTheme()->GetSystemColor( |
201 ui::NativeTheme::kColorId_WindowBackground), | 197 ui::NativeTheme::kColorId_WindowBackground), |
202 0x10))); | 198 0x10))); |
203 | 199 |
204 AddChildView(caption_label); | 200 AddChildView(caption_label); |
205 | 201 |
206 for (size_t i = 0; i < entries.size(); ++i) { | 202 for (size_t i = 0; i < entries.size(); ++i) { |
207 entry_views_.push_back( | 203 entry_views_.push_back(new InfolistEntryView( |
208 new InfolistEntryView(entries[i], title_font_, description_font_)); | 204 entries[i], title_font_list_, description_font_list_)); |
209 AddChildView(entry_views_.back()); | 205 AddChildView(entry_views_.back()); |
210 } | 206 } |
211 } | 207 } |
212 | 208 |
213 InfolistWindow::~InfolistWindow() { | 209 InfolistWindow::~InfolistWindow() { |
214 } | 210 } |
215 | 211 |
216 void InfolistWindow::InitWidget() { | 212 void InfolistWindow::InitWidget() { |
217 views::Widget* widget = views::BubbleDelegateView::CreateBubble(this); | 213 views::Widget* widget = views::BubbleDelegateView::CreateBubble(this); |
218 views::corewm::SetWindowVisibilityAnimationType( | 214 views::corewm::SetWindowVisibilityAnimationType( |
219 widget->GetNativeView(), | 215 widget->GetNativeView(), |
220 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 216 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
221 | 217 |
222 // BubbleFrameView will be initialized through CreateBubble. | 218 // BubbleFrameView will be initialized through CreateBubble. |
223 GetBubbleFrameView()->SetBubbleBorder(new InfolistBorder()); | 219 GetBubbleFrameView()->SetBubbleBorder(new InfolistBorder()); |
224 SizeToContents(); | 220 SizeToContents(); |
225 } | 221 } |
226 | 222 |
227 void InfolistWindow::Relayout(const std::vector<ui::InfolistEntry>& entries) { | 223 void InfolistWindow::Relayout(const std::vector<ui::InfolistEntry>& entries) { |
228 size_t i = 0; | 224 size_t i = 0; |
229 for (; i < entries.size(); ++i) { | 225 for (; i < entries.size(); ++i) { |
230 if (i < entry_views_.size()) { | 226 if (i < entry_views_.size()) { |
231 entry_views_[i]->SetEntry(entries[i]); | 227 entry_views_[i]->SetEntry(entries[i]); |
232 } else { | 228 } else { |
233 InfolistEntryView* new_entry = new InfolistEntryView( | 229 InfolistEntryView* new_entry = new InfolistEntryView( |
234 entries[i], title_font_, description_font_); | 230 entries[i], title_font_list_, description_font_list_); |
235 AddChildView(new_entry); | 231 AddChildView(new_entry); |
236 entry_views_.push_back(new_entry); | 232 entry_views_.push_back(new_entry); |
237 } | 233 } |
238 } | 234 } |
239 | 235 |
240 if (i < entry_views_.size()) { | 236 if (i < entry_views_.size()) { |
241 for (; i < entry_views_.size(); ++i) | 237 for (; i < entry_views_.size(); ++i) |
242 delete entry_views_[i]; | 238 delete entry_views_[i]; |
243 entry_views_.resize(entries.size()); | 239 entry_views_.resize(entries.size()); |
244 } | 240 } |
(...skipping 28 matching lines...) Expand all Loading... | |
273 show_hide_timer_.Stop(); | 269 show_hide_timer_.Stop(); |
274 GetWidget()->Close(); | 270 GetWidget()->Close(); |
275 } | 271 } |
276 | 272 |
277 void InfolistWindow::WindowClosing() { | 273 void InfolistWindow::WindowClosing() { |
278 show_hide_timer_.Stop(); | 274 show_hide_timer_.Stop(); |
279 } | 275 } |
280 | 276 |
281 } // namespace ime | 277 } // namespace ime |
282 } // namespace ash | 278 } // namespace ash |
OLD | NEW |