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