Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 #include "components/toolbar/toolbar_model.h" | 64 #include "components/toolbar/toolbar_model.h" |
| 65 #include "components/translate/core/browser/language_state.h" | 65 #include "components/translate/core/browser/language_state.h" |
| 66 #include "components/zoom/zoom_controller.h" | 66 #include "components/zoom/zoom_controller.h" |
| 67 #include "components/zoom/zoom_event_manager.h" | 67 #include "components/zoom/zoom_event_manager.h" |
| 68 #include "content/public/browser/render_widget_host_view.h" | 68 #include "content/public/browser/render_widget_host_view.h" |
| 69 #include "content/public/browser/web_contents.h" | 69 #include "content/public/browser/web_contents.h" |
| 70 #include "extensions/browser/extension_registry.h" | 70 #include "extensions/browser/extension_registry.h" |
| 71 #include "extensions/common/feature_switch.h" | 71 #include "extensions/common/feature_switch.h" |
| 72 #include "ui/accessibility/ax_view_state.h" | 72 #include "ui/accessibility/ax_view_state.h" |
| 73 #include "ui/base/dragdrop/drag_drop_types.h" | 73 #include "ui/base/dragdrop/drag_drop_types.h" |
| 74 #include "ui/base/material_design/material_design_controller.h" | |
| 75 #include "ui/base/resource/resource_bundle.h" | 74 #include "ui/base/resource/resource_bundle.h" |
| 76 #include "ui/base/theme_provider.h" | 75 #include "ui/base/theme_provider.h" |
| 77 #include "ui/compositor/paint_recorder.h" | 76 #include "ui/compositor/paint_recorder.h" |
| 78 #include "ui/events/event.h" | 77 #include "ui/events/event.h" |
| 79 #include "ui/gfx/animation/slide_animation.h" | 78 #include "ui/gfx/animation/slide_animation.h" |
| 80 #include "ui/gfx/canvas.h" | 79 #include "ui/gfx/canvas.h" |
| 81 #include "ui/gfx/color_palette.h" | 80 #include "ui/gfx/color_palette.h" |
| 82 #include "ui/gfx/color_utils.h" | 81 #include "ui/gfx/color_utils.h" |
| 83 #include "ui/gfx/image/image.h" | 82 #include "ui/gfx/image/image.h" |
| 84 #include "ui/gfx/image/image_skia_operations.h" | 83 #include "ui/gfx/image/image_skia_operations.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, | 165 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, |
| 167 incognito), | 166 incognito), |
| 168 SkColorGetA(kBorderColor)); | 167 SkColorGetA(kBorderColor)); |
| 169 } | 168 } |
| 170 | 169 |
| 171 void LocationBarView::Init() { | 170 void LocationBarView::Init() { |
| 172 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're | 171 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're |
| 173 // not prepared for that. | 172 // not prepared for that. |
| 174 DCHECK(GetWidget()); | 173 DCHECK(GetWidget()); |
| 175 | 174 |
| 176 if (ui::MaterialDesignController::IsModeMaterial()) { | 175 // Make sure children with layers are clipped. See http://crbug.com/589497 |
| 177 // Make sure children with layers are clipped. See http://crbug.com/589497 | 176 SetPaintToLayer(true); |
| 178 SetPaintToLayer(true); | 177 layer()->SetFillsBoundsOpaquely(false); |
| 179 layer()->SetFillsBoundsOpaquely(false); | 178 layer()->SetMasksToBounds(true); |
| 180 layer()->SetMasksToBounds(true); | |
| 181 } else if (is_popup_mode_) { | |
| 182 const int kOmniboxPopupBorderImages[] = | |
| 183 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW); | |
| 184 border_painter_.reset( | |
| 185 views::Painter::CreateImageGridPainter(kOmniboxPopupBorderImages)); | |
| 186 } else { | |
| 187 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 188 const gfx::Insets omnibox_border_insets(14, 9); | |
| 189 border_painter_.reset(views::Painter::CreateImagePainter( | |
| 190 *rb.GetImageSkiaNamed(IDR_OMNIBOX_BORDER), omnibox_border_insets)); | |
| 191 } | |
| 192 | 179 |
| 193 // Determine the main font. | 180 // Determine the main font. |
| 194 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( | 181 gfx::FontList font_list = ResourceBundle::GetSharedInstance().GetFontList( |
| 195 ResourceBundle::BaseFont); | 182 ResourceBundle::BaseFont); |
| 196 const int current_font_size = font_list.GetFontSize(); | 183 const int current_font_size = font_list.GetFontSize(); |
| 197 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); | 184 const int desired_font_size = GetLayoutConstant(OMNIBOX_FONT_PIXEL_SIZE); |
| 198 if (current_font_size != desired_font_size) { | 185 if (current_font_size != desired_font_size) { |
| 199 font_list = | 186 font_list = |
| 200 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); | 187 font_list.DeriveWithSizeDelta(desired_font_size - current_font_size); |
| 201 } | 188 } |
| 202 // Shrink large fonts to make them fit. | 189 // Shrink large fonts to make them fit. |
| 203 // TODO(pkasting): Stretch the location bar instead in this case. | 190 // TODO(pkasting): Stretch the location bar instead in this case. |
| 204 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(); | 191 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(); |
| 205 const int location_height = | 192 const int location_height = |
| 206 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); | 193 std::max(GetPreferredSize().height() - (vertical_padding * 2), 0); |
| 207 font_list = font_list.DeriveWithHeightUpperBound(location_height); | 194 font_list = font_list.DeriveWithHeightUpperBound(location_height); |
| 208 | 195 |
| 209 // Determine the font for use inside the bubbles. | 196 // Determine the font for use inside the bubbles. |
| 210 const int bubble_padding = | 197 const int bubble_padding = |
| 211 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + | 198 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + |
| 212 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); | 199 GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); |
| 213 const int bubble_height = location_height - (bubble_padding * 2); | 200 const int bubble_height = location_height - (bubble_padding * 2); |
| 214 gfx::FontList bubble_font_list = | 201 gfx::FontList chip_font_list = font_list; |
|
Peter Kasting
2016/09/19 23:46:46
Nit: Just use |font_list| below directly
Evan Stade
2016/09/20 17:37:04
Done.
| |
| 215 font_list.DeriveWithHeightUpperBound(bubble_height); | |
| 216 gfx::FontList chip_font_list = ui::MaterialDesignController::IsModeMaterial() | |
| 217 ? font_list | |
| 218 : bubble_font_list; | |
| 219 | 202 |
| 220 const SkColor background_color = GetColor(BACKGROUND); | 203 const SkColor background_color = GetColor(BACKGROUND); |
| 221 location_icon_view_ = | 204 location_icon_view_ = new LocationIconView(chip_font_list, this); |
| 222 new LocationIconView(chip_font_list, background_color, this); | |
| 223 location_icon_view_->set_drag_controller(this); | 205 location_icon_view_->set_drag_controller(this); |
| 224 AddChildView(location_icon_view_); | 206 AddChildView(location_icon_view_); |
| 225 | 207 |
| 226 // Initialize the Omnibox view. | 208 // Initialize the Omnibox view. |
| 227 omnibox_view_ = new OmniboxViewViews( | 209 omnibox_view_ = new OmniboxViewViews( |
| 228 this, profile(), command_updater(), is_popup_mode_, this, font_list); | 210 this, profile(), command_updater(), is_popup_mode_, this, font_list); |
| 229 omnibox_view_->Init(); | 211 omnibox_view_->Init(); |
| 230 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); | 212 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); |
| 231 AddChildView(omnibox_view_); | 213 AddChildView(omnibox_view_); |
| 232 | 214 |
| 233 // Initialize the inline autocomplete view which is visible only when IME is | 215 // Initialize the inline autocomplete view which is visible only when IME is |
| 234 // turned on. Use the same font with the omnibox and highlighted background. | 216 // turned on. Use the same font with the omnibox and highlighted background. |
| 235 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); | 217 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); |
| 236 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 218 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 237 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 219 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
| 238 ime_inline_autocomplete_view_->set_background( | 220 ime_inline_autocomplete_view_->set_background( |
| 239 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 221 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
| 240 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 222 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
| 241 ime_inline_autocomplete_view_->SetEnabledColor( | 223 ime_inline_autocomplete_view_->SetEnabledColor( |
| 242 GetNativeTheme()->GetSystemColor( | 224 GetNativeTheme()->GetSystemColor( |
| 243 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 225 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 244 ime_inline_autocomplete_view_->SetVisible(false); | 226 ime_inline_autocomplete_view_->SetVisible(false); |
| 245 AddChildView(ime_inline_autocomplete_view_); | 227 AddChildView(ime_inline_autocomplete_view_); |
| 246 | 228 |
| 247 const SkColor selected_text_color = GetColor(TEXT); | 229 selected_keyword_view_ = new SelectedKeywordView(chip_font_list, profile()); |
| 248 selected_keyword_view_ = new SelectedKeywordView( | |
| 249 chip_font_list, selected_text_color, background_color, profile()); | |
| 250 AddChildView(selected_keyword_view_); | 230 AddChildView(selected_keyword_view_); |
| 251 | 231 |
| 252 suggested_text_view_ = new views::Label(base::string16(), font_list); | 232 suggested_text_view_ = new views::Label(base::string16(), font_list); |
| 253 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 233 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 254 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 234 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
| 255 suggested_text_view_->SetEnabledColor( | 235 suggested_text_view_->SetEnabledColor( |
| 256 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); | 236 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); |
| 257 suggested_text_view_->SetVisible(false); | 237 suggested_text_view_->SetVisible(false); |
| 258 AddChildView(suggested_text_view_); | 238 AddChildView(suggested_text_view_); |
| 259 | 239 |
| 240 gfx::FontList bubble_font_list = | |
| 241 font_list.DeriveWithHeightUpperBound(bubble_height); | |
| 260 keyword_hint_view_ = new KeywordHintView( | 242 keyword_hint_view_ = new KeywordHintView( |
| 261 profile(), font_list, bubble_font_list, location_height, | 243 profile(), font_list, bubble_font_list, location_height, |
| 262 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); | 244 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); |
| 263 AddChildView(keyword_hint_view_); | 245 AddChildView(keyword_hint_view_); |
| 264 | 246 |
| 265 ScopedVector<ContentSettingImageModel> models = | 247 ScopedVector<ContentSettingImageModel> models = |
| 266 ContentSettingImageModel::GenerateContentSettingImageModels(); | 248 ContentSettingImageModel::GenerateContentSettingImageModels(); |
| 267 for (ContentSettingImageModel* model : models.get()) { | 249 for (ContentSettingImageModel* model : models.get()) { |
| 268 // ContentSettingImageView takes ownership of its model. | 250 // ContentSettingImageView takes ownership of its model. |
| 269 ContentSettingImageView* image_view = new ContentSettingImageView( | 251 ContentSettingImageView* image_view = |
| 270 model, this, chip_font_list, background_color); | 252 new ContentSettingImageView(model, this, chip_font_list); |
| 271 content_setting_views_.push_back(image_view); | 253 content_setting_views_.push_back(image_view); |
| 272 image_view->SetVisible(false); | 254 image_view->SetVisible(false); |
| 273 AddChildView(image_view); | 255 AddChildView(image_view); |
| 274 } | 256 } |
| 275 models.weak_clear(); | 257 models.weak_clear(); |
| 276 | 258 |
| 277 zoom_view_ = new ZoomView(delegate_); | 259 zoom_view_ = new ZoomView(delegate_); |
| 278 AddChildView(zoom_view_); | 260 AddChildView(zoom_view_); |
| 279 | 261 |
| 280 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); | 262 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 302 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 321 | 303 |
| 322 case SELECTED_TEXT: | 304 case SELECTED_TEXT: |
| 323 return native_theme->GetSystemColor( | 305 return native_theme->GetSystemColor( |
| 324 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 306 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
| 325 | 307 |
| 326 case DEEMPHASIZED_TEXT: | 308 case DEEMPHASIZED_TEXT: |
| 327 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); | 309 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); |
| 328 | 310 |
| 329 case SECURITY_CHIP_TEXT: | 311 case SECURITY_CHIP_TEXT: |
| 330 return ui::MaterialDesignController::IsModeMaterial() | 312 return GetSecureTextColor(GetToolbarModel()->GetSecurityLevel(false)); |
| 331 ? GetSecureTextColor( | |
| 332 GetToolbarModel()->GetSecurityLevel(false)) | |
| 333 : SkColorSetRGB(7, 149, 0); | |
| 334 } | 313 } |
| 335 NOTREACHED(); | 314 NOTREACHED(); |
| 336 return gfx::kPlaceholderColor; | 315 return gfx::kPlaceholderColor; |
| 337 } | 316 } |
| 338 | 317 |
| 339 SkColor LocationBarView::GetSecureTextColor( | 318 SkColor LocationBarView::GetSecureTextColor( |
| 340 security_state::SecurityStateModel::SecurityLevel security_level) const { | 319 security_state::SecurityStateModel::SecurityLevel security_level) const { |
| 341 if (security_level == | 320 if (security_level == |
| 342 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { | 321 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { |
| 343 return GetColor(DEEMPHASIZED_TEXT); | 322 return GetColor(DEEMPHASIZED_TEXT); |
| 344 } | 323 } |
| 345 | 324 |
| 346 SkColor text_color = GetColor(TEXT); | 325 SkColor text_color = GetColor(TEXT); |
| 347 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || | 326 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || |
| 348 (security_level == security_state::SecurityStateModel::SECURE) || | 327 (security_level == security_state::SecurityStateModel::SECURE) || |
| 349 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { | 328 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { |
| 350 if (ui::MaterialDesignController::IsModeMaterial()) { | 329 if (color_utils::IsDark(GetColor(BACKGROUND))) |
| 351 if (color_utils::IsDark(GetColor(BACKGROUND))) | 330 return text_color; |
| 352 return text_color; | 331 text_color = |
| 353 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) | 332 (security_level == security_state::SecurityStateModel::SECURITY_ERROR) |
| 354 text_color = gfx::kGoogleRed700; | 333 ? gfx::kGoogleRed700 |
| 355 else | 334 : gfx::kGoogleGreen700; |
| 356 text_color = gfx::kGoogleGreen700; | |
| 357 } else if (security_level == | |
| 358 security_state::SecurityStateModel::SECURITY_ERROR) { | |
| 359 text_color = SkColorSetRGB(162, 0, 0); | |
| 360 } else { | |
| 361 text_color = GetColor(SECURITY_CHIP_TEXT); | |
| 362 } | |
| 363 } | 335 } |
|
Peter Kasting
2016/09/19 23:46:45
Nit: If we pull out the SECURITY_ERROR case we can
Evan Stade
2016/09/20 17:37:04
refactored slightly so we don't have to make that
Peter Kasting
2016/09/20 20:18:05
Technically this is a behavior change since we now
Evan Stade
2016/09/21 17:05:00
yea. I actually think we shouldn't have to call Ge
| |
| 364 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); | 336 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); |
| 365 } | 337 } |
| 366 | 338 |
| 367 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { | 339 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 368 DCHECK(zoom_view_); | 340 DCHECK(zoom_view_); |
| 369 if (RefreshZoomView()) { | 341 if (RefreshZoomView()) { |
| 370 Layout(); | 342 Layout(); |
| 371 SchedulePaint(); | 343 SchedulePaint(); |
| 372 } | 344 } |
| 373 | 345 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 } | 386 } |
| 415 | 387 |
| 416 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { | 388 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { |
| 417 gfx::Point origin(omnibox_view_->bounds().origin()); | 389 gfx::Point origin(omnibox_view_->bounds().origin()); |
| 418 origin.set_x(GetMirroredXInView(origin.x())); | 390 origin.set_x(GetMirroredXInView(origin.x())); |
| 419 views::View::ConvertPointToScreen(this, &origin); | 391 views::View::ConvertPointToScreen(this, &origin); |
| 420 return origin; | 392 return origin; |
| 421 } | 393 } |
| 422 | 394 |
| 423 int LocationBarView::GetLocationIconWidth() const { | 395 int LocationBarView::GetLocationIconWidth() const { |
| 424 if (ui::MaterialDesignController::IsModeMaterial()) { | 396 constexpr int kVectorIconSize = 16; |
| 425 constexpr int kVectorIconSize = 16; | 397 return kVectorIconSize; |
|
Peter Kasting
2016/09/19 23:46:46
Nit: Since this is no longer computed at runtime,
Evan Stade
2016/09/20 17:37:04
Done.
| |
| 426 return kVectorIconSize; | |
| 427 } | |
| 428 return GetThemeProvider()->GetImageSkiaNamed( | |
| 429 AutocompleteMatch::TypeToIcon( | |
| 430 AutocompleteMatchType::URL_WHAT_YOU_TYPED))->width(); | |
| 431 } | 398 } |
| 432 | 399 |
| 433 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { | 400 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { |
| 434 ime_inline_autocomplete_view_->SetText(text); | 401 ime_inline_autocomplete_view_->SetText(text); |
| 435 ime_inline_autocomplete_view_->SetVisible(!text.empty()); | 402 ime_inline_autocomplete_view_->SetVisible(!text.empty()); |
| 436 } | 403 } |
| 437 | 404 |
| 438 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { | 405 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { |
| 439 if (suggested_text_view_->text() != text) { | 406 if (suggested_text_view_->text() != text) { |
| 440 suggested_text_view_->SetText(text); | 407 suggested_text_view_->SetText(text); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 469 void LocationBarView::GetOmniboxPopupPositioningInfo( | 436 void LocationBarView::GetOmniboxPopupPositioningInfo( |
| 470 gfx::Point* top_left_screen_coord, | 437 gfx::Point* top_left_screen_coord, |
| 471 int* popup_width, | 438 int* popup_width, |
| 472 int* left_margin, | 439 int* left_margin, |
| 473 int* right_margin, | 440 int* right_margin, |
| 474 int top_edge_overlap) { | 441 int top_edge_overlap) { |
| 475 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); | 442 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); |
| 476 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); | 443 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); |
| 477 | 444 |
| 478 *popup_width = parent()->width(); | 445 *popup_width = parent()->width(); |
| 479 gfx::Rect location_bar_bounds(bounds()); | 446 gfx::Rect location_bar_bounds(bounds()); |
|
Peter Kasting
2016/09/19 23:46:45
Nit: Just use x() and bounds.right() directly belo
Evan Stade
2016/09/20 17:37:04
Done.
| |
| 480 if (!ui::MaterialDesignController::IsModeMaterial()) | |
| 481 location_bar_bounds.Inset(GetHorizontalEdgeThickness(), 0); | |
| 482 *left_margin = location_bar_bounds.x(); | 447 *left_margin = location_bar_bounds.x(); |
| 483 *right_margin = *popup_width - location_bar_bounds.right(); | 448 *right_margin = *popup_width - location_bar_bounds.right(); |
| 484 } | 449 } |
| 485 | 450 |
| 486 //////////////////////////////////////////////////////////////////////////////// | 451 //////////////////////////////////////////////////////////////////////////////// |
| 487 // LocationBarView, public LocationBar implementation: | 452 // LocationBarView, public LocationBar implementation: |
| 488 | 453 |
| 489 void LocationBarView::FocusLocation(bool select_all) { | 454 void LocationBarView::FocusLocation(bool select_all) { |
| 490 omnibox_view_->SetFocus(); | 455 omnibox_view_->SetFocus(); |
| 491 if (select_all) | 456 if (select_all) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 507 return omnibox_view_->model()->has_focus(); | 472 return omnibox_view_->model()->has_focus(); |
| 508 } | 473 } |
| 509 | 474 |
| 510 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { | 475 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { |
| 511 state->role = ui::AX_ROLE_GROUP; | 476 state->role = ui::AX_ROLE_GROUP; |
| 512 } | 477 } |
| 513 | 478 |
| 514 gfx::Size LocationBarView::GetPreferredSize() const { | 479 gfx::Size LocationBarView::GetPreferredSize() const { |
| 515 // Compute minimum height. | 480 // Compute minimum height. |
| 516 gfx::Size min_size; | 481 gfx::Size min_size; |
| 517 if (ui::MaterialDesignController::IsModeMaterial() || is_popup_mode_) { | 482 min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT)); |
|
Peter Kasting
2016/09/19 23:46:45
Nit: Maybe:
gfx::Size min_size(0, GetLayoutCons
Evan Stade
2016/09/20 17:37:04
Done.
| |
| 518 min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT)); | |
| 519 } else { | |
| 520 min_size = border_painter_->GetMinimumSize(); | |
| 521 } | |
| 522 | 483 |
| 523 if (!IsInitialized()) | 484 if (!IsInitialized()) |
| 524 return min_size; | 485 return min_size; |
| 525 | 486 |
| 526 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); | 487 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); |
| 527 | 488 |
| 528 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 489 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 529 | 490 |
| 530 // Compute width of omnibox-leading content. | 491 // Compute width of omnibox-leading content. |
| 531 const int edge_thickness = GetHorizontalEdgeThickness(); | 492 const int edge_thickness = GetHorizontalEdgeThickness(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 545 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
| 585 // to position our child views in this case, because other things may be | 546 // to position our child views in this case, because other things may be |
| 586 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 547 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
| 587 // hits ctrl-d). | 548 // hits ctrl-d). |
| 588 const int bubble_horizontal_padding = | 549 const int bubble_horizontal_padding = |
| 589 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); | 550 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); |
| 590 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(); | 551 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(); |
| 591 const int location_height = std::max(height() - (vertical_padding * 2), 0); | 552 const int location_height = std::max(height() - (vertical_padding * 2), 0); |
| 592 | 553 |
| 593 location_icon_view_->SetLabel(base::string16()); | 554 location_icon_view_->SetLabel(base::string16()); |
| 594 location_icon_view_->SetBackground(false); | |
| 595 if (ShouldShowKeywordBubble()) { | 555 if (ShouldShowKeywordBubble()) { |
| 596 leading_decorations.AddDecoration(vertical_padding, location_height, true, | 556 leading_decorations.AddDecoration(vertical_padding, location_height, true, |
| 597 0, bubble_horizontal_padding, | 557 0, bubble_horizontal_padding, |
| 598 item_padding, selected_keyword_view_); | 558 item_padding, selected_keyword_view_); |
| 599 if (selected_keyword_view_->keyword() != keyword) { | 559 if (selected_keyword_view_->keyword() != keyword) { |
| 600 selected_keyword_view_->SetKeyword(keyword); | 560 selected_keyword_view_->SetKeyword(keyword); |
| 601 const TemplateURL* template_url = | 561 const TemplateURL* template_url = |
| 602 TemplateURLServiceFactory::GetForProfile(profile())-> | 562 TemplateURLServiceFactory::GetForProfile(profile())-> |
| 603 GetTemplateURLForKeyword(keyword); | 563 GetTemplateURLForKeyword(keyword); |
| 604 if (template_url && | 564 if (template_url && |
| 605 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { | 565 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 606 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> | 566 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> |
| 607 GetOmniboxIcon(template_url->GetExtensionId()); | 567 GetOmniboxIcon(template_url->GetExtensionId()); |
| 608 selected_keyword_view_->SetImage(image.AsImageSkia()); | 568 selected_keyword_view_->SetImage(image.AsImageSkia()); |
| 609 selected_keyword_view_->set_is_extension_icon(true); | |
| 610 } else { | 569 } else { |
| 611 selected_keyword_view_->ResetImage(); | 570 selected_keyword_view_->ResetImage(); |
| 612 selected_keyword_view_->set_is_extension_icon(false); | |
| 613 } | 571 } |
| 614 } | 572 } |
| 615 } else if (ShouldShowSecurityChip()) { | 573 } else if (ShouldShowSecurityChip()) { |
| 616 location_icon_view_->SetLabel(GetSecurityText()); | 574 location_icon_view_->SetLabel(GetSecurityText()); |
| 617 location_icon_view_->SetBackground(true); | |
| 618 // The largest fraction of the omnibox that can be taken by the EV bubble. | 575 // The largest fraction of the omnibox that can be taken by the EV bubble. |
| 619 const double kMaxBubbleFraction = 0.5; | 576 const double kMaxBubbleFraction = 0.5; |
| 620 leading_decorations.AddDecoration( | 577 leading_decorations.AddDecoration( |
| 621 vertical_padding, location_height, false, kMaxBubbleFraction, | 578 vertical_padding, location_height, false, kMaxBubbleFraction, |
| 622 bubble_horizontal_padding, item_padding, location_icon_view_); | 579 bubble_horizontal_padding, item_padding, location_icon_view_); |
| 623 } else { | 580 } else { |
| 624 leading_decorations.AddDecoration(vertical_padding, location_height, | 581 leading_decorations.AddDecoration(vertical_padding, location_height, |
| 625 location_icon_view_); | 582 location_icon_view_); |
| 626 } | 583 } |
| 627 | 584 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 x = entry_width - width; | 724 x = entry_width - width; |
| 768 location_bounds.set_width(x); | 725 location_bounds.set_width(x); |
| 769 ime_inline_autocomplete_view_->SetBounds( | 726 ime_inline_autocomplete_view_->SetBounds( |
| 770 location_bounds.right(), location_bounds.y(), | 727 location_bounds.right(), location_bounds.y(), |
| 771 std::min(width, entry_width), location_bounds.height()); | 728 std::min(width, entry_width), location_bounds.height()); |
| 772 } | 729 } |
| 773 omnibox_view_->SetBoundsRect(location_bounds); | 730 omnibox_view_->SetBoundsRect(location_bounds); |
| 774 } | 731 } |
| 775 | 732 |
| 776 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 733 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 777 if (ui::MaterialDesignController::IsModeMaterial()) { | 734 RefreshLocationIcon(); |
| 778 RefreshLocationIcon(); | 735 if (!is_popup_mode_) { |
| 779 if (!is_popup_mode_) { | 736 set_background( |
| 780 set_background(new BackgroundWith1PxBorder(GetColor(BACKGROUND), | 737 new BackgroundWith1PxBorder(GetColor(BACKGROUND), kBorderColor)); |
| 781 kBorderColor)); | |
| 782 } | |
| 783 } | 738 } |
| 784 } | 739 } |
| 785 | 740 |
| 786 void LocationBarView::Update(const WebContents* contents) { | 741 void LocationBarView::Update(const WebContents* contents) { |
| 787 RefreshContentSettingViews(); | 742 RefreshContentSettingViews(); |
| 788 RefreshZoomView(); | 743 RefreshZoomView(); |
| 789 RefreshPageActionViews(); | 744 RefreshPageActionViews(); |
| 790 RefreshTranslateIcon(); | 745 RefreshTranslateIcon(); |
| 791 RefreshSaveCreditCardIconView(); | 746 RefreshSaveCreditCardIconView(); |
| 792 RefreshManagePasswordsIconView(); | 747 RefreshManagePasswordsIconView(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 return view->visible() ? | 789 return view->visible() ? |
| 835 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + | 790 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + |
| 836 view->GetMinimumSize().width()) : 0; | 791 view->GetMinimumSize().width()) : 0; |
| 837 } | 792 } |
| 838 | 793 |
| 839 int LocationBarView::GetHorizontalEdgeThickness() const { | 794 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 840 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); | 795 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); |
| 841 } | 796 } |
| 842 | 797 |
| 843 int LocationBarView::GetVerticalEdgeThickness() const { | 798 int LocationBarView::GetVerticalEdgeThickness() const { |
| 844 if (ui::MaterialDesignController::IsModeMaterial()) | 799 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); |
|
Peter Kasting
2016/09/19 23:46:46
Nit: At this point I'd inline this into the caller
Evan Stade
2016/09/20 17:37:04
done, renamed the ...WithPadding fn to GetTotalVer
| |
| 845 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); | |
| 846 return is_popup_mode_ ? views::NonClientFrameView::kClientEdgeThickness | |
| 847 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); | |
| 848 } | 800 } |
| 849 | 801 |
| 850 int LocationBarView::GetVerticalEdgeThicknessWithPadding() const { | 802 int LocationBarView::GetVerticalEdgeThicknessWithPadding() const { |
| 851 return GetVerticalEdgeThickness() + | 803 return GetVerticalEdgeThickness() + |
| 852 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); | 804 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); |
| 853 } | 805 } |
| 854 | 806 |
| 855 void LocationBarView::RefreshLocationIcon() { | 807 void LocationBarView::RefreshLocationIcon() { |
| 856 // |omnibox_view_| may not be ready yet if Init() has not been called. The | 808 // |omnibox_view_| may not be ready yet if Init() has not been called. The |
| 857 // icon will be set soon by OnChanged(). | 809 // icon will be set soon by OnChanged(). |
| 858 if (!omnibox_view_) | 810 if (!omnibox_view_) |
| 859 return; | 811 return; |
| 860 | 812 |
| 861 if (ui::MaterialDesignController::IsModeMaterial()) { | 813 security_state::SecurityStateModel::SecurityLevel security_level = |
| 862 security_state::SecurityStateModel::SecurityLevel security_level = | 814 GetToolbarModel()->GetSecurityLevel(false); |
| 863 GetToolbarModel()->GetSecurityLevel(false); | 815 SkColor icon_color = |
| 864 SkColor icon_color = | 816 (security_level == security_state::SecurityStateModel::NONE) |
| 865 (security_level == security_state::SecurityStateModel::NONE) | 817 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) |
| 866 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) | 818 : GetSecureTextColor(security_level); |
| 867 : GetSecureTextColor(security_level); | 819 location_icon_view_->SetImage(gfx::CreateVectorIcon( |
| 868 location_icon_view_->SetImage(gfx::CreateVectorIcon( | 820 omnibox_view_->GetVectorIcon(), GetLocationIconWidth(), icon_color)); |
| 869 omnibox_view_->GetVectorIcon(), GetLocationIconWidth(), icon_color)); | |
| 870 } else { | |
| 871 location_icon_view_->SetImage( | |
| 872 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); | |
| 873 } | |
| 874 } | 821 } |
| 875 | 822 |
| 876 bool LocationBarView::RefreshContentSettingViews() { | 823 bool LocationBarView::RefreshContentSettingViews() { |
| 877 bool visibility_changed = false; | 824 bool visibility_changed = false; |
| 878 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 825 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 879 i != content_setting_views_.end(); ++i) { | 826 i != content_setting_views_.end(); ++i) { |
| 880 const bool was_visible = (*i)->visible(); | 827 const bool was_visible = (*i)->visible(); |
| 881 (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr | 828 (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr |
| 882 : GetWebContents()); | 829 : GetWebContents()); |
| 883 if (was_visible != (*i)->visible()) | 830 if (was_visible != (*i)->visible()) |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1262 popup->UpdatePopupAppearance(); | 1209 popup->UpdatePopupAppearance(); |
| 1263 } | 1210 } |
| 1264 | 1211 |
| 1265 void LocationBarView::OnFocus() { | 1212 void LocationBarView::OnFocus() { |
| 1266 omnibox_view_->SetFocus(); | 1213 omnibox_view_->SetFocus(); |
| 1267 } | 1214 } |
| 1268 | 1215 |
| 1269 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 1216 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 1270 View::OnPaint(canvas); | 1217 View::OnPaint(canvas); |
| 1271 | 1218 |
| 1272 if (ui::MaterialDesignController::IsModeMaterial()) { | 1219 if (show_focus_rect_ && omnibox_view_->HasFocus()) { |
| 1273 if (show_focus_rect_ && omnibox_view_->HasFocus()) { | 1220 SkPaint paint; |
| 1274 SkPaint paint; | 1221 paint.setAntiAlias(true); |
| 1275 paint.setAntiAlias(true); | 1222 paint.setColor(GetNativeTheme()->GetSystemColor( |
| 1276 paint.setColor(GetNativeTheme()->GetSystemColor( | 1223 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor)); |
| 1277 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor)); | 1224 paint.setStyle(SkPaint::kStroke_Style); |
| 1278 paint.setStyle(SkPaint::kStroke_Style); | 1225 paint.setStrokeWidth(1); |
| 1279 paint.setStrokeWidth(1); | 1226 gfx::RectF focus_rect(GetLocalBounds()); |
| 1280 gfx::RectF focus_rect(GetLocalBounds()); | 1227 focus_rect.Inset(gfx::InsetsF(0.5f)); |
| 1281 focus_rect.Inset(gfx::InsetsF(0.5f)); | 1228 canvas->DrawRoundRect(focus_rect, |
| 1282 canvas->DrawRoundRect( | 1229 BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint); |
| 1283 focus_rect, BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint); | |
| 1284 } | |
| 1285 if (!is_popup_mode_) | |
| 1286 return; // The background and border are painted by our Background. | |
| 1287 } | 1230 } |
| 1231 if (!is_popup_mode_) | |
| 1232 return; // The background and border are painted by our Background. | |
| 1288 | 1233 |
| 1289 // Fill the location bar background color behind the border. Parts of the | 1234 // Fill the location bar background color behind the border. Parts of the |
| 1290 // border images are meant to rest atop the toolbar background and parts atop | 1235 // border images are meant to rest atop the toolbar background and parts atop |
| 1291 // the omnibox background, so we can't just blindly fill our entire bounds. | 1236 // the omnibox background, so we can't just blindly fill our entire bounds. |
| 1292 gfx::Rect bounds(GetContentsBounds()); | 1237 gfx::Rect bounds(GetContentsBounds()); |
| 1293 bounds.Inset(GetHorizontalEdgeThickness(), | 1238 bounds.Inset(GetHorizontalEdgeThickness(), |
| 1294 is_popup_mode_ ? 0 : GetVerticalEdgeThickness()); | 1239 is_popup_mode_ ? 0 : GetVerticalEdgeThickness()); |
| 1295 SkColor background_color(GetColor(BACKGROUND)); | 1240 SkColor background_color(GetColor(BACKGROUND)); |
| 1296 if (!is_popup_mode_) { | |
| 1297 SkPaint paint; | |
| 1298 paint.setStyle(SkPaint::kFill_Style); | |
| 1299 paint.setColor(background_color); | |
| 1300 const int kBorderCornerRadius = 2; | |
| 1301 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | |
| 1302 // The border itself will be drawn in PaintChildren() since it includes an | |
| 1303 // inner shadow which should be drawn over the contents. | |
| 1304 return; | |
| 1305 } | |
| 1306 | |
| 1307 canvas->FillRect(bounds, background_color); | 1241 canvas->FillRect(bounds, background_color); |
| 1308 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); | 1242 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); |
| 1309 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); | 1243 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); |
| 1310 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); | 1244 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); |
| 1311 } | 1245 } |
| 1312 | 1246 |
| 1313 void LocationBarView::PaintChildren(const ui::PaintContext& context) { | |
| 1314 View::PaintChildren(context); | |
| 1315 ui::PaintRecorder recorder(context, size()); | |
| 1316 | |
| 1317 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | |
| 1318 // the focus rect to appear on top of children we paint here rather than | |
| 1319 // OnPaint(). | |
| 1320 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | |
| 1321 if (!ui::MaterialDesignController::IsModeMaterial() && show_focus_rect_ && | |
| 1322 HasFocus()) | |
| 1323 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); | |
| 1324 | |
| 1325 if (!ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_) { | |
| 1326 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), | |
| 1327 GetContentsBounds()); | |
| 1328 } | |
| 1329 } | |
| 1330 | |
| 1331 //////////////////////////////////////////////////////////////////////////////// | 1247 //////////////////////////////////////////////////////////////////////////////// |
| 1332 // LocationBarView, private views::DragController implementation: | 1248 // LocationBarView, private views::DragController implementation: |
| 1333 | 1249 |
| 1334 void LocationBarView::WriteDragDataForView(views::View* sender, | 1250 void LocationBarView::WriteDragDataForView(views::View* sender, |
| 1335 const gfx::Point& press_pt, | 1251 const gfx::Point& press_pt, |
| 1336 OSExchangeData* data) { | 1252 OSExchangeData* data) { |
| 1337 DCHECK_NE(GetDragOperationsForView(sender, press_pt), | 1253 DCHECK_NE(GetDragOperationsForView(sender, press_pt), |
| 1338 ui::DragDropTypes::DRAG_NONE); | 1254 ui::DragDropTypes::DRAG_NONE); |
| 1339 | 1255 |
| 1340 WebContents* web_contents = GetWebContents(); | 1256 WebContents* web_contents = GetWebContents(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1397 // LocationBarView, private TemplateURLServiceObserver implementation: | 1313 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1398 | 1314 |
| 1399 void LocationBarView::OnTemplateURLServiceChanged() { | 1315 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1400 template_url_service_->RemoveObserver(this); | 1316 template_url_service_->RemoveObserver(this); |
| 1401 template_url_service_ = nullptr; | 1317 template_url_service_ = nullptr; |
| 1402 // If the browser is no longer active, let's not show the info bubble, as this | 1318 // If the browser is no longer active, let's not show the info bubble, as this |
| 1403 // would make the browser the active window again. | 1319 // would make the browser the active window again. |
| 1404 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1320 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1405 ShowFirstRunBubble(); | 1321 ShowFirstRunBubble(); |
| 1406 } | 1322 } |
| OLD | NEW |