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/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 // Determine the font for use inside the bubbles. The bubble background | 205 // Determine the font for use inside the bubbles. The bubble background |
206 // images have 1 px thick edges, which we don't want to overlap. | 206 // images have 1 px thick edges, which we don't want to overlap. |
207 const int kBubbleInteriorVerticalPadding = 1; | 207 const int kBubbleInteriorVerticalPadding = 1; |
208 const int bubble_vertical_padding = | 208 const int bubble_vertical_padding = |
209 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2; | 209 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2; |
210 const gfx::FontList bubble_font_list(font_list.DeriveWithHeightUpperBound( | 210 const gfx::FontList bubble_font_list(font_list.DeriveWithHeightUpperBound( |
211 location_height - bubble_vertical_padding)); | 211 location_height - bubble_vertical_padding)); |
212 | 212 |
213 const SkColor background_color = | 213 const SkColor background_color = |
214 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); | 214 GetColor(ConnectionSecurityHelper::NONE, LocationBarView::BACKGROUND); |
215 ev_bubble_view_ = new EVBubbleView( | 215 ev_bubble_view_ = new EVBubbleView( |
216 bubble_font_list, GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), | 216 bubble_font_list, |
| 217 GetColor(ConnectionSecurityHelper::EV_SECURE, SECURITY_TEXT), |
217 background_color, this); | 218 background_color, this); |
218 ev_bubble_view_->set_drag_controller(this); | 219 ev_bubble_view_->set_drag_controller(this); |
219 AddChildView(ev_bubble_view_); | 220 AddChildView(ev_bubble_view_); |
220 | 221 |
221 // Initialize the Omnibox view. | 222 // Initialize the Omnibox view. |
222 omnibox_view_ = new OmniboxViewViews( | 223 omnibox_view_ = new OmniboxViewViews( |
223 this, profile(), command_updater(), is_popup_mode_, this, font_list); | 224 this, profile(), command_updater(), is_popup_mode_, this, font_list); |
224 omnibox_view_->Init(); | 225 omnibox_view_->Init(); |
225 omnibox_view_->SetFocusable(true); | 226 omnibox_view_->SetFocusable(true); |
226 AddChildView(omnibox_view_); | 227 AddChildView(omnibox_view_); |
227 | 228 |
228 // Initialize the inline autocomplete view which is visible only when IME is | 229 // Initialize the inline autocomplete view which is visible only when IME is |
229 // turned on. Use the same font with the omnibox and highlighted background. | 230 // turned on. Use the same font with the omnibox and highlighted background. |
230 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); | 231 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); |
231 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 232 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
232 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 233 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
233 ime_inline_autocomplete_view_->set_background( | 234 ime_inline_autocomplete_view_->set_background( |
234 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 235 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
235 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 236 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
236 ime_inline_autocomplete_view_->SetEnabledColor( | 237 ime_inline_autocomplete_view_->SetEnabledColor( |
237 GetNativeTheme()->GetSystemColor( | 238 GetNativeTheme()->GetSystemColor( |
238 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 239 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
239 ime_inline_autocomplete_view_->SetVisible(false); | 240 ime_inline_autocomplete_view_->SetVisible(false); |
240 AddChildView(ime_inline_autocomplete_view_); | 241 AddChildView(ime_inline_autocomplete_view_); |
241 | 242 |
242 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); | 243 const SkColor text_color = GetColor(ConnectionSecurityHelper::NONE, TEXT); |
243 selected_keyword_view_ = new SelectedKeywordView( | 244 selected_keyword_view_ = new SelectedKeywordView( |
244 bubble_font_list, text_color, background_color, profile()); | 245 bubble_font_list, text_color, background_color, profile()); |
245 AddChildView(selected_keyword_view_); | 246 AddChildView(selected_keyword_view_); |
246 | 247 |
247 suggested_text_view_ = new views::Label(base::string16(), font_list); | 248 suggested_text_view_ = new views::Label(base::string16(), font_list); |
248 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 249 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
249 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 250 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
250 suggested_text_view_->SetEnabledColor(GetColor( | 251 suggested_text_view_->SetEnabledColor(GetColor( |
251 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | 252 ConnectionSecurityHelper::NONE, LocationBarView::DEEMPHASIZED_TEXT)); |
252 suggested_text_view_->SetVisible(false); | 253 suggested_text_view_->SetVisible(false); |
253 AddChildView(suggested_text_view_); | 254 AddChildView(suggested_text_view_); |
254 | 255 |
255 keyword_hint_view_ = new KeywordHintView( | 256 keyword_hint_view_ = new KeywordHintView( |
256 profile(), font_list, | 257 profile(), font_list, GetColor(ConnectionSecurityHelper::NONE, |
257 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), | 258 LocationBarView::DEEMPHASIZED_TEXT), |
258 background_color); | 259 background_color); |
259 AddChildView(keyword_hint_view_); | 260 AddChildView(keyword_hint_view_); |
260 | 261 |
261 mic_search_view_ = new views::ImageButton(this); | 262 mic_search_view_ = new views::ImageButton(this); |
262 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); | 263 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); |
263 mic_search_view_->SetAccessibilityFocusable(true); | 264 mic_search_view_->SetAccessibilityFocusable(true); |
264 mic_search_view_->SetTooltipText( | 265 mic_search_view_->SetTooltipText( |
265 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); | 266 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); |
266 mic_search_view_->SetImage( | 267 mic_search_view_->SetImage( |
267 views::Button::STATE_NORMAL, | 268 views::Button::STATE_NORMAL, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 // visible when the location entry has just been initialized. | 307 // visible when the location entry has just been initialized. |
307 Update(NULL); | 308 Update(NULL); |
308 | 309 |
309 size_animation_.Reset(1); | 310 size_animation_.Reset(1); |
310 } | 311 } |
311 | 312 |
312 bool LocationBarView::IsInitialized() const { | 313 bool LocationBarView::IsInitialized() const { |
313 return omnibox_view_ != NULL; | 314 return omnibox_view_ != NULL; |
314 } | 315 } |
315 | 316 |
316 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, | 317 SkColor LocationBarView::GetColor( |
317 ColorKind kind) const { | 318 ConnectionSecurityHelper::SecurityLevel security_level, |
| 319 ColorKind kind) const { |
318 const ui::NativeTheme* native_theme = GetNativeTheme(); | 320 const ui::NativeTheme* native_theme = GetNativeTheme(); |
319 switch (kind) { | 321 switch (kind) { |
320 case BACKGROUND: | 322 case BACKGROUND: |
321 return native_theme->GetSystemColor( | 323 return native_theme->GetSystemColor( |
322 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | 324 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
323 | 325 |
324 case TEXT: | 326 case TEXT: |
325 return native_theme->GetSystemColor( | 327 return native_theme->GetSystemColor( |
326 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 328 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
327 | 329 |
328 case SELECTED_TEXT: | 330 case SELECTED_TEXT: |
329 return native_theme->GetSystemColor( | 331 return native_theme->GetSystemColor( |
330 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 332 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
331 | 333 |
332 case DEEMPHASIZED_TEXT: | 334 case DEEMPHASIZED_TEXT: |
333 return color_utils::AlphaBlend( | 335 return color_utils::AlphaBlend( |
334 GetColor(security_level, TEXT), | 336 GetColor(security_level, TEXT), |
335 GetColor(security_level, BACKGROUND), | 337 GetColor(security_level, BACKGROUND), |
336 128); | 338 128); |
337 | 339 |
338 case SECURITY_TEXT: { | 340 case SECURITY_TEXT: { |
339 SkColor color; | 341 SkColor color; |
340 switch (security_level) { | 342 switch (security_level) { |
341 case ToolbarModel::EV_SECURE: | 343 case ConnectionSecurityHelper::EV_SECURE: |
342 case ToolbarModel::SECURE: | 344 case ConnectionSecurityHelper::SECURE: |
343 color = SkColorSetRGB(7, 149, 0); | 345 color = SkColorSetRGB(7, 149, 0); |
344 break; | 346 break; |
345 | 347 |
346 case ToolbarModel::SECURITY_WARNING: | 348 case ConnectionSecurityHelper::SECURITY_WARNING: |
347 case ToolbarModel::SECURITY_POLICY_WARNING: | 349 case ConnectionSecurityHelper::SECURITY_POLICY_WARNING: |
348 return GetColor(security_level, DEEMPHASIZED_TEXT); | 350 return GetColor(security_level, DEEMPHASIZED_TEXT); |
349 break; | 351 break; |
350 | 352 |
351 case ToolbarModel::SECURITY_ERROR: | 353 case ConnectionSecurityHelper::SECURITY_ERROR: |
352 color = SkColorSetRGB(162, 0, 0); | 354 color = SkColorSetRGB(162, 0, 0); |
353 break; | 355 break; |
354 | 356 |
355 default: | 357 default: |
356 NOTREACHED(); | 358 NOTREACHED(); |
357 return GetColor(security_level, TEXT); | 359 return GetColor(security_level, TEXT); |
358 } | 360 } |
359 return color_utils::GetReadableColor( | 361 return color_utils::GetReadableColor( |
360 color, GetColor(security_level, BACKGROUND)); | 362 color, GetColor(security_level, BACKGROUND)); |
361 } | 363 } |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 return suggested_text_view_->visible() && | 993 return suggested_text_view_->visible() && |
992 !suggested_text_view_->size().IsEmpty(); | 994 !suggested_text_view_->size().IsEmpty(); |
993 } | 995 } |
994 | 996 |
995 bool LocationBarView::ShouldShowKeywordBubble() const { | 997 bool LocationBarView::ShouldShowKeywordBubble() const { |
996 return !omnibox_view_->model()->keyword().empty() && | 998 return !omnibox_view_->model()->keyword().empty() && |
997 !omnibox_view_->model()->is_keyword_hint(); | 999 !omnibox_view_->model()->is_keyword_hint(); |
998 } | 1000 } |
999 | 1001 |
1000 bool LocationBarView::ShouldShowEVBubble() const { | 1002 bool LocationBarView::ShouldShowEVBubble() const { |
1001 return | 1003 return (GetToolbarModel()->GetSecurityLevel(false) == |
1002 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); | 1004 ConnectionSecurityHelper::EV_SECURE); |
1003 } | 1005 } |
1004 | 1006 |
1005 //////////////////////////////////////////////////////////////////////////////// | 1007 //////////////////////////////////////////////////////////////////////////////// |
1006 // LocationBarView, private LocationBar implementation: | 1008 // LocationBarView, private LocationBar implementation: |
1007 | 1009 |
1008 void LocationBarView::ShowFirstRunBubble() { | 1010 void LocationBarView::ShowFirstRunBubble() { |
1009 // Wait until search engines have loaded to show the first run bubble. | 1011 // Wait until search engines have loaded to show the first run bubble. |
1010 TemplateURLService* url_service = | 1012 TemplateURLService* url_service = |
1011 TemplateURLServiceFactory::GetForProfile(profile()); | 1013 TemplateURLServiceFactory::GetForProfile(profile()); |
1012 if (!url_service->loaded()) { | 1014 if (!url_service->loaded()) { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 } | 1215 } |
1214 | 1216 |
1215 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 1217 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
1216 View::OnPaint(canvas); | 1218 View::OnPaint(canvas); |
1217 | 1219 |
1218 // Fill the location bar background color behind the border. Parts of the | 1220 // Fill the location bar background color behind the border. Parts of the |
1219 // border images are meant to rest atop the toolbar background and parts atop | 1221 // border images are meant to rest atop the toolbar background and parts atop |
1220 // the omnibox background, so we can't just blindly fill our entire bounds. | 1222 // the omnibox background, so we can't just blindly fill our entire bounds. |
1221 gfx::Rect bounds(GetContentsBounds()); | 1223 gfx::Rect bounds(GetContentsBounds()); |
1222 bounds.Inset(GetHorizontalEdgeThickness(), vertical_edge_thickness()); | 1224 bounds.Inset(GetHorizontalEdgeThickness(), vertical_edge_thickness()); |
1223 SkColor color(GetColor(ToolbarModel::NONE, BACKGROUND)); | 1225 SkColor color(GetColor(ConnectionSecurityHelper::NONE, BACKGROUND)); |
1224 if (is_popup_mode_) { | 1226 if (is_popup_mode_) { |
1225 canvas->FillRect(bounds, color); | 1227 canvas->FillRect(bounds, color); |
1226 } else { | 1228 } else { |
1227 SkPaint paint; | 1229 SkPaint paint; |
1228 paint.setStyle(SkPaint::kFill_Style); | 1230 paint.setStyle(SkPaint::kFill_Style); |
1229 paint.setColor(color); | 1231 paint.setColor(color); |
1230 const int kBorderCornerRadius = 2; | 1232 const int kBorderCornerRadius = 2; |
1231 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1233 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
1232 } | 1234 } |
1233 | 1235 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 | 1366 |
1365 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1367 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1366 const SearchModel::State& new_state) { | 1368 const SearchModel::State& new_state) { |
1367 const bool visible = !GetToolbarModel()->input_in_progress() && | 1369 const bool visible = !GetToolbarModel()->input_in_progress() && |
1368 new_state.voice_search_supported; | 1370 new_state.voice_search_supported; |
1369 if (mic_search_view_->visible() != visible) { | 1371 if (mic_search_view_->visible() != visible) { |
1370 mic_search_view_->SetVisible(visible); | 1372 mic_search_view_->SetVisible(visible); |
1371 Layout(); | 1373 Layout(); |
1372 } | 1374 } |
1373 } | 1375 } |
OLD | NEW |