| 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(ConnectionSecurityHelper::NONE, LocationBarView::BACKGROUND); | 214 GetColor(ConnectionSecurityStatus::NONE, LocationBarView::BACKGROUND); |
| 215 ev_bubble_view_ = new EVBubbleView( | 215 ev_bubble_view_ = new EVBubbleView( |
| 216 bubble_font_list, | 216 bubble_font_list, |
| 217 GetColor(ConnectionSecurityHelper::EV_SECURE, SECURITY_TEXT), | 217 GetColor(ConnectionSecurityStatus::EV_SECURE, SECURITY_TEXT), |
| 218 background_color, this); | 218 background_color, this); |
| 219 ev_bubble_view_->set_drag_controller(this); | 219 ev_bubble_view_->set_drag_controller(this); |
| 220 AddChildView(ev_bubble_view_); | 220 AddChildView(ev_bubble_view_); |
| 221 | 221 |
| 222 // Initialize the Omnibox view. | 222 // Initialize the Omnibox view. |
| 223 omnibox_view_ = new OmniboxViewViews( | 223 omnibox_view_ = new OmniboxViewViews( |
| 224 this, profile(), command_updater(), is_popup_mode_, this, font_list); | 224 this, profile(), command_updater(), is_popup_mode_, this, font_list); |
| 225 omnibox_view_->Init(); | 225 omnibox_view_->Init(); |
| 226 omnibox_view_->SetFocusable(true); | 226 omnibox_view_->SetFocusable(true); |
| 227 AddChildView(omnibox_view_); | 227 AddChildView(omnibox_view_); |
| 228 | 228 |
| 229 // 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 |
| 230 // 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. |
| 231 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); | 231 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); |
| 232 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 232 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 233 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 233 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
| 234 ime_inline_autocomplete_view_->set_background( | 234 ime_inline_autocomplete_view_->set_background( |
| 235 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 235 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
| 236 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 236 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
| 237 ime_inline_autocomplete_view_->SetEnabledColor( | 237 ime_inline_autocomplete_view_->SetEnabledColor( |
| 238 GetNativeTheme()->GetSystemColor( | 238 GetNativeTheme()->GetSystemColor( |
| 239 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 239 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 240 ime_inline_autocomplete_view_->SetVisible(false); | 240 ime_inline_autocomplete_view_->SetVisible(false); |
| 241 AddChildView(ime_inline_autocomplete_view_); | 241 AddChildView(ime_inline_autocomplete_view_); |
| 242 | 242 |
| 243 const SkColor text_color = GetColor(ConnectionSecurityHelper::NONE, TEXT); | 243 const SkColor text_color = GetColor(ConnectionSecurityStatus::NONE, TEXT); |
| 244 selected_keyword_view_ = new SelectedKeywordView( | 244 selected_keyword_view_ = new SelectedKeywordView( |
| 245 bubble_font_list, text_color, background_color, profile()); | 245 bubble_font_list, text_color, background_color, profile()); |
| 246 AddChildView(selected_keyword_view_); | 246 AddChildView(selected_keyword_view_); |
| 247 | 247 |
| 248 suggested_text_view_ = new views::Label(base::string16(), font_list); | 248 suggested_text_view_ = new views::Label(base::string16(), font_list); |
| 249 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 249 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 250 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 250 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
| 251 suggested_text_view_->SetEnabledColor(GetColor( | 251 suggested_text_view_->SetEnabledColor(GetColor( |
| 252 ConnectionSecurityHelper::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | 252 ConnectionSecurityStatus::NONE, LocationBarView::DEEMPHASIZED_TEXT)); |
| 253 suggested_text_view_->SetVisible(false); | 253 suggested_text_view_->SetVisible(false); |
| 254 AddChildView(suggested_text_view_); | 254 AddChildView(suggested_text_view_); |
| 255 | 255 |
| 256 keyword_hint_view_ = new KeywordHintView( | 256 keyword_hint_view_ = new KeywordHintView( |
| 257 profile(), font_list, GetColor(ConnectionSecurityHelper::NONE, | 257 profile(), font_list, GetColor(ConnectionSecurityStatus::NONE, |
| 258 LocationBarView::DEEMPHASIZED_TEXT), | 258 LocationBarView::DEEMPHASIZED_TEXT), |
| 259 background_color); | 259 background_color); |
| 260 AddChildView(keyword_hint_view_); | 260 AddChildView(keyword_hint_view_); |
| 261 | 261 |
| 262 mic_search_view_ = new views::ImageButton(this); | 262 mic_search_view_ = new views::ImageButton(this); |
| 263 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); | 263 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); |
| 264 mic_search_view_->SetAccessibilityFocusable(true); | 264 mic_search_view_->SetAccessibilityFocusable(true); |
| 265 mic_search_view_->SetTooltipText( | 265 mic_search_view_->SetTooltipText( |
| 266 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); | 266 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); |
| 267 mic_search_view_->SetImage( | 267 mic_search_view_->SetImage( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 Update(NULL); | 308 Update(NULL); |
| 309 | 309 |
| 310 size_animation_.Reset(1); | 310 size_animation_.Reset(1); |
| 311 } | 311 } |
| 312 | 312 |
| 313 bool LocationBarView::IsInitialized() const { | 313 bool LocationBarView::IsInitialized() const { |
| 314 return omnibox_view_ != NULL; | 314 return omnibox_view_ != NULL; |
| 315 } | 315 } |
| 316 | 316 |
| 317 SkColor LocationBarView::GetColor( | 317 SkColor LocationBarView::GetColor( |
| 318 ConnectionSecurityHelper::SecurityLevel security_level, | 318 ConnectionSecurityStatus::SecurityLevel security_level, |
| 319 ColorKind kind) const { | 319 ColorKind kind) const { |
| 320 const ui::NativeTheme* native_theme = GetNativeTheme(); | 320 const ui::NativeTheme* native_theme = GetNativeTheme(); |
| 321 switch (kind) { | 321 switch (kind) { |
| 322 case BACKGROUND: | 322 case BACKGROUND: |
| 323 return native_theme->GetSystemColor( | 323 return native_theme->GetSystemColor( |
| 324 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | 324 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| 325 | 325 |
| 326 case TEXT: | 326 case TEXT: |
| 327 return native_theme->GetSystemColor( | 327 return native_theme->GetSystemColor( |
| 328 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 328 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 329 | 329 |
| 330 case SELECTED_TEXT: | 330 case SELECTED_TEXT: |
| 331 return native_theme->GetSystemColor( | 331 return native_theme->GetSystemColor( |
| 332 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 332 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
| 333 | 333 |
| 334 case DEEMPHASIZED_TEXT: | 334 case DEEMPHASIZED_TEXT: |
| 335 return color_utils::AlphaBlend( | 335 return color_utils::AlphaBlend( |
| 336 GetColor(security_level, TEXT), | 336 GetColor(security_level, TEXT), |
| 337 GetColor(security_level, BACKGROUND), | 337 GetColor(security_level, BACKGROUND), |
| 338 128); | 338 128); |
| 339 | 339 |
| 340 case SECURITY_TEXT: { | 340 case SECURITY_TEXT: { |
| 341 SkColor color; | 341 SkColor color; |
| 342 switch (security_level) { | 342 switch (security_level) { |
| 343 case ConnectionSecurityHelper::EV_SECURE: | 343 case ConnectionSecurityStatus::EV_SECURE: |
| 344 case ConnectionSecurityHelper::SECURE: | 344 case ConnectionSecurityStatus::SECURE: |
| 345 color = SkColorSetRGB(7, 149, 0); | 345 color = SkColorSetRGB(7, 149, 0); |
| 346 break; | 346 break; |
| 347 | 347 |
| 348 case ConnectionSecurityHelper::SECURITY_WARNING: | 348 case ConnectionSecurityStatus::SECURITY_WARNING: |
| 349 case ConnectionSecurityHelper::SECURITY_POLICY_WARNING: | 349 case ConnectionSecurityStatus::SECURITY_POLICY_WARNING: |
| 350 return GetColor(security_level, DEEMPHASIZED_TEXT); | 350 return GetColor(security_level, DEEMPHASIZED_TEXT); |
| 351 break; | 351 break; |
| 352 | 352 |
| 353 case ConnectionSecurityHelper::SECURITY_ERROR: | 353 case ConnectionSecurityStatus::SECURITY_ERROR: |
| 354 color = SkColorSetRGB(162, 0, 0); | 354 color = SkColorSetRGB(162, 0, 0); |
| 355 break; | 355 break; |
| 356 | 356 |
| 357 default: | 357 default: |
| 358 NOTREACHED(); | 358 NOTREACHED(); |
| 359 return GetColor(security_level, TEXT); | 359 return GetColor(security_level, TEXT); |
| 360 } | 360 } |
| 361 return color_utils::GetReadableColor( | 361 return color_utils::GetReadableColor( |
| 362 color, GetColor(security_level, BACKGROUND)); | 362 color, GetColor(security_level, BACKGROUND)); |
| 363 } | 363 } |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 !suggested_text_view_->size().IsEmpty(); | 994 !suggested_text_view_->size().IsEmpty(); |
| 995 } | 995 } |
| 996 | 996 |
| 997 bool LocationBarView::ShouldShowKeywordBubble() const { | 997 bool LocationBarView::ShouldShowKeywordBubble() const { |
| 998 return !omnibox_view_->model()->keyword().empty() && | 998 return !omnibox_view_->model()->keyword().empty() && |
| 999 !omnibox_view_->model()->is_keyword_hint(); | 999 !omnibox_view_->model()->is_keyword_hint(); |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 bool LocationBarView::ShouldShowEVBubble() const { | 1002 bool LocationBarView::ShouldShowEVBubble() const { |
| 1003 return (GetToolbarModel()->GetSecurityLevel(false) == | 1003 return (GetToolbarModel()->GetSecurityLevel(false) == |
| 1004 ConnectionSecurityHelper::EV_SECURE); | 1004 ConnectionSecurityStatus::EV_SECURE); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 //////////////////////////////////////////////////////////////////////////////// | 1007 //////////////////////////////////////////////////////////////////////////////// |
| 1008 // LocationBarView, private LocationBar implementation: | 1008 // LocationBarView, private LocationBar implementation: |
| 1009 | 1009 |
| 1010 void LocationBarView::ShowFirstRunBubble() { | 1010 void LocationBarView::ShowFirstRunBubble() { |
| 1011 // 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. |
| 1012 TemplateURLService* url_service = | 1012 TemplateURLService* url_service = |
| 1013 TemplateURLServiceFactory::GetForProfile(profile()); | 1013 TemplateURLServiceFactory::GetForProfile(profile()); |
| 1014 if (!url_service->loaded()) { | 1014 if (!url_service->loaded()) { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 } | 1215 } |
| 1216 | 1216 |
| 1217 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 1217 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 1218 View::OnPaint(canvas); | 1218 View::OnPaint(canvas); |
| 1219 | 1219 |
| 1220 // 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 |
| 1221 // 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 |
| 1222 // 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. |
| 1223 gfx::Rect bounds(GetContentsBounds()); | 1223 gfx::Rect bounds(GetContentsBounds()); |
| 1224 bounds.Inset(GetHorizontalEdgeThickness(), vertical_edge_thickness()); | 1224 bounds.Inset(GetHorizontalEdgeThickness(), vertical_edge_thickness()); |
| 1225 SkColor color(GetColor(ConnectionSecurityHelper::NONE, BACKGROUND)); | 1225 SkColor color(GetColor(ConnectionSecurityStatus::NONE, BACKGROUND)); |
| 1226 if (is_popup_mode_) { | 1226 if (is_popup_mode_) { |
| 1227 canvas->FillRect(bounds, color); | 1227 canvas->FillRect(bounds, color); |
| 1228 } else { | 1228 } else { |
| 1229 SkPaint paint; | 1229 SkPaint paint; |
| 1230 paint.setStyle(SkPaint::kFill_Style); | 1230 paint.setStyle(SkPaint::kFill_Style); |
| 1231 paint.setColor(color); | 1231 paint.setColor(color); |
| 1232 const int kBorderCornerRadius = 2; | 1232 const int kBorderCornerRadius = 2; |
| 1233 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1233 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 | 1366 |
| 1367 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1367 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
| 1368 const SearchModel::State& new_state) { | 1368 const SearchModel::State& new_state) { |
| 1369 const bool visible = !GetToolbarModel()->input_in_progress() && | 1369 const bool visible = !GetToolbarModel()->input_in_progress() && |
| 1370 new_state.voice_search_supported; | 1370 new_state.voice_search_supported; |
| 1371 if (mic_search_view_->visible() != visible) { | 1371 if (mic_search_view_->visible() != visible) { |
| 1372 mic_search_view_->SetVisible(visible); | 1372 mic_search_view_->SetVisible(visible); |
| 1373 Layout(); | 1373 Layout(); |
| 1374 } | 1374 } |
| 1375 } | 1375 } |
| OLD | NEW |