| 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 ResourceBundle::BaseFont); | 249 ResourceBundle::BaseFont); |
| 250 const int current_font_size = font_list.GetFontSize(); | 250 const int current_font_size = font_list.GetFontSize(); |
| 251 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize; | 251 const int desired_font_size = browser_defaults::kOmniboxFontPixelSize; |
| 252 if (current_font_size < desired_font_size) | 252 if (current_font_size < desired_font_size) |
| 253 font_list = font_list.DeriveFontListWithSize(desired_font_size); | 253 font_list = font_list.DeriveFontListWithSize(desired_font_size); |
| 254 // Shrink large fonts to make them fit. | 254 // Shrink large fonts to make them fit. |
| 255 // TODO(pkasting): Stretch the location bar instead in this case. | 255 // TODO(pkasting): Stretch the location bar instead in this case. |
| 256 int location_height = GetInternalHeight(true); | 256 int location_height = GetInternalHeight(true); |
| 257 int font_y_offset; | 257 int font_y_offset; |
| 258 CalculateFontAndOffsetForHeight(location_height, &font_list, &font_y_offset); | 258 CalculateFontAndOffsetForHeight(location_height, &font_list, &font_y_offset); |
| 259 const gfx::Font& font = font_list.GetPrimaryFont(); | |
| 260 | 259 |
| 261 // Determine the font for use inside the bubbles. | 260 // Determine the font for use inside the bubbles. |
| 262 gfx::FontList bubble_font_list(font_list); | 261 gfx::FontList bubble_font_list(font_list); |
| 263 int bubble_font_y_offset; | 262 int bubble_font_y_offset; |
| 264 // The bubble background images have 1 px thick edges, which we don't want to | 263 // The bubble background images have 1 px thick edges, which we don't want to |
| 265 // overlap. | 264 // overlap. |
| 266 const int kBubbleInteriorVerticalPadding = 1; | 265 const int kBubbleInteriorVerticalPadding = 1; |
| 267 CalculateFontAndOffsetForHeight( | 266 CalculateFontAndOffsetForHeight( |
| 268 location_height - ((kBubblePadding + kBubbleInteriorVerticalPadding) * 2), | 267 location_height - ((kBubblePadding + kBubbleInteriorVerticalPadding) * 2), |
| 269 &bubble_font_list, &bubble_font_y_offset); | 268 &bubble_font_list, &bubble_font_y_offset); |
| 270 bubble_font_y_offset += kBubbleInteriorVerticalPadding; | 269 bubble_font_y_offset += kBubbleInteriorVerticalPadding; |
| 271 const gfx::Font& bubble_font = font_list.GetPrimaryFont(); | |
| 272 | 270 |
| 273 const SkColor background_color = | 271 const SkColor background_color = |
| 274 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); | 272 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); |
| 275 ev_bubble_view_ = new EVBubbleView( | 273 ev_bubble_view_ = new EVBubbleView( |
| 276 bubble_font, bubble_font_y_offset, | 274 bubble_font_list, bubble_font_y_offset, |
| 277 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), background_color, this); | 275 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), background_color, this); |
| 278 ev_bubble_view_->set_drag_controller(this); | 276 ev_bubble_view_->set_drag_controller(this); |
| 279 AddChildView(ev_bubble_view_); | 277 AddChildView(ev_bubble_view_); |
| 280 | 278 |
| 281 // Initialize the Omnibox view. | 279 // Initialize the Omnibox view. |
| 282 location_entry_.reset(CreateOmniboxView(this, profile_, command_updater_, | 280 location_entry_.reset(CreateOmniboxView(this, profile_, command_updater_, |
| 283 is_popup_mode_, this, font_list, | 281 is_popup_mode_, this, font_list, |
| 284 font_y_offset)); | 282 font_y_offset)); |
| 285 SetLocationEntryFocusable(true); | 283 SetLocationEntryFocusable(true); |
| 286 location_entry_view_ = location_entry_->AddToView(this); | 284 location_entry_view_ = location_entry_->AddToView(this); |
| 287 | 285 |
| 288 // Initialize the inline autocomplete view which is visible only when IME is | 286 // Initialize the inline autocomplete view which is visible only when IME is |
| 289 // turned on. Use the same font with the omnibox and highlighted background. | 287 // turned on. Use the same font with the omnibox and highlighted background. |
| 290 ime_inline_autocomplete_view_ = new views::Label(string16(), font); | 288 ime_inline_autocomplete_view_ = new views::Label(string16(), font_list); |
| 291 { | 289 ime_inline_autocomplete_view_->set_border( |
| 292 // views::Label (|ime_inline_autocomplete_view_|) supports only gfx::Font | 290 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); |
| 293 // and ignores the rest of fonts but the first in |font_list| while | |
| 294 // views::Textfield (|location_entry_view_|) supports gfx::FontList and | |
| 295 // layouts text based on all fonts in the list. Thus the font height and | |
| 296 // baseline can be different between them. We add padding to align them | |
| 297 // on the same baseline. | |
| 298 // TODO(yukishiino): Remove this hack once views::Label supports | |
| 299 // gfx::FontList. | |
| 300 const int baseline_diff = location_entry_view_->GetBaseline() - | |
| 301 ime_inline_autocomplete_view_->GetBaseline(); | |
| 302 ime_inline_autocomplete_view_->set_border( | |
| 303 views::Border::CreateEmptyBorder( | |
| 304 font_y_offset + baseline_diff, 0, 0, 0)); | |
| 305 } | |
| 306 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 291 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 307 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 292 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
| 308 ime_inline_autocomplete_view_->set_background( | 293 ime_inline_autocomplete_view_->set_background( |
| 309 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 294 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
| 310 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 295 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
| 311 ime_inline_autocomplete_view_->SetEnabledColor( | 296 ime_inline_autocomplete_view_->SetEnabledColor( |
| 312 GetNativeTheme()->GetSystemColor( | 297 GetNativeTheme()->GetSystemColor( |
| 313 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 298 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 314 ime_inline_autocomplete_view_->SetVisible(false); | 299 ime_inline_autocomplete_view_->SetVisible(false); |
| 315 AddChildView(ime_inline_autocomplete_view_); | 300 AddChildView(ime_inline_autocomplete_view_); |
| 316 | 301 |
| 317 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); | 302 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); |
| 318 selected_keyword_view_ = new SelectedKeywordView( | 303 selected_keyword_view_ = new SelectedKeywordView( |
| 319 bubble_font, bubble_font_y_offset, text_color, background_color, | 304 bubble_font_list, bubble_font_y_offset, text_color, background_color, |
| 320 profile_); | 305 profile_); |
| 321 AddChildView(selected_keyword_view_); | 306 AddChildView(selected_keyword_view_); |
| 322 | 307 |
| 323 suggested_text_view_ = new views::Label(string16(), font); | 308 suggested_text_view_ = new views::Label(string16(), font_list); |
| 324 suggested_text_view_->set_border( | 309 suggested_text_view_->set_border( |
| 325 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); | 310 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); |
| 326 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 311 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 327 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 312 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
| 328 suggested_text_view_->SetEnabledColor(GetColor( | 313 suggested_text_view_->SetEnabledColor(GetColor( |
| 329 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | 314 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); |
| 330 suggested_text_view_->SetVisible(false); | 315 suggested_text_view_->SetVisible(false); |
| 331 AddChildView(suggested_text_view_); | 316 AddChildView(suggested_text_view_); |
| 332 | 317 |
| 333 keyword_hint_view_ = new KeywordHintView( | 318 keyword_hint_view_ = new KeywordHintView( |
| 334 profile_, font, font_y_offset, | 319 profile_, font_list, font_y_offset, |
| 335 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), | 320 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), |
| 336 background_color); | 321 background_color); |
| 337 AddChildView(keyword_hint_view_); | 322 AddChildView(keyword_hint_view_); |
| 338 | 323 |
| 339 mic_search_view_ = new views::ImageButton(this); | 324 mic_search_view_ = new views::ImageButton(this); |
| 340 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); | 325 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); |
| 341 mic_search_view_->set_accessibility_focusable(true); | 326 mic_search_view_->set_accessibility_focusable(true); |
| 342 mic_search_view_->SetTooltipText( | 327 mic_search_view_->SetTooltipText( |
| 343 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); | 328 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); |
| 344 mic_search_view_->SetImage( | 329 mic_search_view_->SetImage( |
| 345 views::Button::STATE_NORMAL, | 330 views::Button::STATE_NORMAL, |
| 346 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 331 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 347 IDR_OMNIBOX_MIC_SEARCH)); | 332 IDR_OMNIBOX_MIC_SEARCH)); |
| 348 mic_search_view_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 333 mic_search_view_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 349 views::ImageButton::ALIGN_MIDDLE); | 334 views::ImageButton::ALIGN_MIDDLE); |
| 350 mic_search_view_->SetVisible(false); | 335 mic_search_view_->SetVisible(false); |
| 351 InitTouchableLocationBarChildView(mic_search_view_); | 336 InitTouchableLocationBarChildView(mic_search_view_); |
| 352 AddChildView(mic_search_view_); | 337 AddChildView(mic_search_view_); |
| 353 | 338 |
| 354 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 339 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 355 ContentSettingImageView* content_blocked_view = | 340 ContentSettingImageView* content_blocked_view = |
| 356 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, | 341 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, |
| 357 bubble_font, bubble_font_y_offset, | 342 bubble_font_list, bubble_font_y_offset, |
| 358 text_color, background_color); | 343 text_color, background_color); |
| 359 content_setting_views_.push_back(content_blocked_view); | 344 content_setting_views_.push_back(content_blocked_view); |
| 360 content_blocked_view->SetVisible(false); | 345 content_blocked_view->SetVisible(false); |
| 361 AddChildView(content_blocked_view); | 346 AddChildView(content_blocked_view); |
| 362 } | 347 } |
| 363 | 348 |
| 364 generated_credit_card_view_ = new GeneratedCreditCardView(delegate_); | 349 generated_credit_card_view_ = new GeneratedCreditCardView(delegate_); |
| 365 AddChildView(generated_credit_card_view_); | 350 AddChildView(generated_credit_card_view_); |
| 366 | 351 |
| 367 zoom_view_ = new ZoomView(delegate_); | 352 zoom_view_ = new ZoomView(delegate_); |
| (...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 bounds.Inset(-(horizontal_padding + 1) / 2, 0); | 1564 bounds.Inset(-(horizontal_padding + 1) / 2, 0); |
| 1580 location_bar_util::PaintExtensionActionBackground( | 1565 location_bar_util::PaintExtensionActionBackground( |
| 1581 *(*page_action_view)->image_view()->page_action(), | 1566 *(*page_action_view)->image_view()->page_action(), |
| 1582 tab_id, canvas, bounds, text_color, background_color); | 1567 tab_id, canvas, bounds, text_color, background_color); |
| 1583 } | 1568 } |
| 1584 } | 1569 } |
| 1585 | 1570 |
| 1586 void LocationBarView::AccessibilitySetValue(const string16& new_value) { | 1571 void LocationBarView::AccessibilitySetValue(const string16& new_value) { |
| 1587 location_entry_->SetUserText(new_value); | 1572 location_entry_->SetUserText(new_value); |
| 1588 } | 1573 } |
| OLD | NEW |