Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 2348853004: Remove non-md code in location bar (Views). (Closed)
Patch Set: remove unused fn Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 = GetTotalVerticalPadding();
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 =
215 font_list.DeriveWithHeightUpperBound(bubble_height);
216 gfx::FontList chip_font_list = ui::MaterialDesignController::IsModeMaterial()
217 ? font_list
218 : bubble_font_list;
219 201
220 const SkColor background_color = GetColor(BACKGROUND); 202 const SkColor background_color = GetColor(BACKGROUND);
221 location_icon_view_ = 203 location_icon_view_ = new LocationIconView(font_list, this);
222 new LocationIconView(chip_font_list, background_color, this);
223 location_icon_view_->set_drag_controller(this); 204 location_icon_view_->set_drag_controller(this);
224 AddChildView(location_icon_view_); 205 AddChildView(location_icon_view_);
225 206
226 // Initialize the Omnibox view. 207 // Initialize the Omnibox view.
227 omnibox_view_ = new OmniboxViewViews( 208 omnibox_view_ = new OmniboxViewViews(
228 this, profile(), command_updater(), is_popup_mode_, this, font_list); 209 this, profile(), command_updater(), is_popup_mode_, this, font_list);
229 omnibox_view_->Init(); 210 omnibox_view_->Init();
230 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS); 211 omnibox_view_->SetFocusBehavior(FocusBehavior::ALWAYS);
231 AddChildView(omnibox_view_); 212 AddChildView(omnibox_view_);
232 213
233 // Initialize the inline autocomplete view which is visible only when IME is 214 // 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. 215 // turned on. Use the same font with the omnibox and highlighted background.
235 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); 216 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list);
236 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 217 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
237 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 218 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
238 ime_inline_autocomplete_view_->set_background( 219 ime_inline_autocomplete_view_->set_background(
239 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( 220 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
240 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 221 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
241 ime_inline_autocomplete_view_->SetEnabledColor( 222 ime_inline_autocomplete_view_->SetEnabledColor(
242 GetNativeTheme()->GetSystemColor( 223 GetNativeTheme()->GetSystemColor(
243 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 224 ui::NativeTheme::kColorId_TextfieldSelectionColor));
244 ime_inline_autocomplete_view_->SetVisible(false); 225 ime_inline_autocomplete_view_->SetVisible(false);
245 AddChildView(ime_inline_autocomplete_view_); 226 AddChildView(ime_inline_autocomplete_view_);
246 227
247 const SkColor selected_text_color = GetColor(TEXT); 228 selected_keyword_view_ = new SelectedKeywordView(font_list, profile());
248 selected_keyword_view_ = new SelectedKeywordView(
249 chip_font_list, selected_text_color, background_color, profile());
250 AddChildView(selected_keyword_view_); 229 AddChildView(selected_keyword_view_);
251 230
252 suggested_text_view_ = new views::Label(base::string16(), font_list); 231 suggested_text_view_ = new views::Label(base::string16(), font_list);
253 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 232 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
254 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 233 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
255 suggested_text_view_->SetEnabledColor( 234 suggested_text_view_->SetEnabledColor(
256 GetColor(LocationBarView::DEEMPHASIZED_TEXT)); 235 GetColor(LocationBarView::DEEMPHASIZED_TEXT));
257 suggested_text_view_->SetVisible(false); 236 suggested_text_view_->SetVisible(false);
258 AddChildView(suggested_text_view_); 237 AddChildView(suggested_text_view_);
259 238
239 gfx::FontList bubble_font_list =
240 font_list.DeriveWithHeightUpperBound(bubble_height);
260 keyword_hint_view_ = new KeywordHintView( 241 keyword_hint_view_ = new KeywordHintView(
261 profile(), font_list, bubble_font_list, location_height, 242 profile(), font_list, bubble_font_list, location_height,
262 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); 243 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color);
263 AddChildView(keyword_hint_view_); 244 AddChildView(keyword_hint_view_);
264 245
265 ScopedVector<ContentSettingImageModel> models = 246 ScopedVector<ContentSettingImageModel> models =
266 ContentSettingImageModel::GenerateContentSettingImageModels(); 247 ContentSettingImageModel::GenerateContentSettingImageModels();
267 for (ContentSettingImageModel* model : models.get()) { 248 for (ContentSettingImageModel* model : models.get()) {
268 // ContentSettingImageView takes ownership of its model. 249 // ContentSettingImageView takes ownership of its model.
269 ContentSettingImageView* image_view = new ContentSettingImageView( 250 ContentSettingImageView* image_view =
270 model, this, chip_font_list, background_color); 251 new ContentSettingImageView(model, this, font_list);
271 content_setting_views_.push_back(image_view); 252 content_setting_views_.push_back(image_view);
272 image_view->SetVisible(false); 253 image_view->SetVisible(false);
273 AddChildView(image_view); 254 AddChildView(image_view);
274 } 255 }
275 models.weak_clear(); 256 models.weak_clear();
276 257
277 zoom_view_ = new ZoomView(delegate_); 258 zoom_view_ = new ZoomView(delegate_);
278 AddChildView(zoom_view_); 259 AddChildView(zoom_view_);
279 260
280 open_pdf_in_reader_view_ = new OpenPDFInReaderView(); 261 open_pdf_in_reader_view_ = new OpenPDFInReaderView();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 ui::NativeTheme::kColorId_TextfieldDefaultColor); 301 ui::NativeTheme::kColorId_TextfieldDefaultColor);
321 302
322 case SELECTED_TEXT: 303 case SELECTED_TEXT:
323 return native_theme->GetSystemColor( 304 return native_theme->GetSystemColor(
324 ui::NativeTheme::kColorId_TextfieldSelectionColor); 305 ui::NativeTheme::kColorId_TextfieldSelectionColor);
325 306
326 case DEEMPHASIZED_TEXT: 307 case DEEMPHASIZED_TEXT:
327 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); 308 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128);
328 309
329 case SECURITY_CHIP_TEXT: 310 case SECURITY_CHIP_TEXT:
330 return ui::MaterialDesignController::IsModeMaterial() 311 return GetSecureTextColor(GetToolbarModel()->GetSecurityLevel(false));
331 ? GetSecureTextColor(
332 GetToolbarModel()->GetSecurityLevel(false))
333 : SkColorSetRGB(7, 149, 0);
334 } 312 }
335 NOTREACHED(); 313 NOTREACHED();
336 return gfx::kPlaceholderColor; 314 return gfx::kPlaceholderColor;
337 } 315 }
338 316
339 SkColor LocationBarView::GetSecureTextColor( 317 SkColor LocationBarView::GetSecureTextColor(
340 security_state::SecurityStateModel::SecurityLevel security_level) const { 318 security_state::SecurityStateModel::SecurityLevel security_level) const {
341 if (security_level == 319 if (security_level ==
342 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { 320 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) {
343 return GetColor(DEEMPHASIZED_TEXT); 321 return GetColor(DEEMPHASIZED_TEXT);
344 } 322 }
345 323
346 SkColor text_color = GetColor(TEXT); 324 SkColor text_color = GetColor(TEXT);
347 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || 325 if (!color_utils::IsDark(GetColor(BACKGROUND))) {
348 (security_level == security_state::SecurityStateModel::SECURE) || 326 if ((security_level == security_state::SecurityStateModel::EV_SECURE) ||
349 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { 327 (security_level == security_state::SecurityStateModel::SECURE)) {
350 if (ui::MaterialDesignController::IsModeMaterial()) { 328 text_color = gfx::kGoogleGreen700;
351 if (color_utils::IsDark(GetColor(BACKGROUND)))
352 return text_color;
353 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR)
354 text_color = gfx::kGoogleRed700;
355 else
356 text_color = gfx::kGoogleGreen700;
357 } else if (security_level == 329 } else if (security_level ==
358 security_state::SecurityStateModel::SECURITY_ERROR) { 330 security_state::SecurityStateModel::SECURITY_ERROR) {
359 text_color = SkColorSetRGB(162, 0, 0); 331 text_color = gfx::kGoogleRed700;
360 } else {
361 text_color = GetColor(SECURITY_CHIP_TEXT);
362 } 332 }
363 } 333 }
364 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); 334 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND));
365 } 335 }
366 336
367 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { 337 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
368 DCHECK(zoom_view_); 338 DCHECK(zoom_view_);
369 if (RefreshZoomView()) { 339 if (RefreshZoomView()) {
370 Layout(); 340 Layout();
371 SchedulePaint(); 341 SchedulePaint();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 star_view_->SetToggled(on); 383 star_view_->SetToggled(on);
414 } 384 }
415 385
416 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { 386 gfx::Point LocationBarView::GetOmniboxViewOrigin() const {
417 gfx::Point origin(omnibox_view_->bounds().origin()); 387 gfx::Point origin(omnibox_view_->bounds().origin());
418 origin.set_x(GetMirroredXInView(origin.x())); 388 origin.set_x(GetMirroredXInView(origin.x()));
419 views::View::ConvertPointToScreen(this, &origin); 389 views::View::ConvertPointToScreen(this, &origin);
420 return origin; 390 return origin;
421 } 391 }
422 392
423 int LocationBarView::GetLocationIconWidth() const {
424 if (ui::MaterialDesignController::IsModeMaterial()) {
425 constexpr int kVectorIconSize = 16;
426 return kVectorIconSize;
427 }
428 return GetThemeProvider()->GetImageSkiaNamed(
429 AutocompleteMatch::TypeToIcon(
430 AutocompleteMatchType::URL_WHAT_YOU_TYPED))->width();
431 }
432
433 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { 393 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) {
434 ime_inline_autocomplete_view_->SetText(text); 394 ime_inline_autocomplete_view_->SetText(text);
435 ime_inline_autocomplete_view_->SetVisible(!text.empty()); 395 ime_inline_autocomplete_view_->SetVisible(!text.empty());
436 } 396 }
437 397
438 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { 398 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) {
439 if (suggested_text_view_->text() != text) { 399 if (suggested_text_view_->text() != text) {
440 suggested_text_view_->SetText(text); 400 suggested_text_view_->SetText(text);
441 suggested_text_view_->SetVisible(!text.empty()); 401 suggested_text_view_->SetVisible(!text.empty());
442 Layout(); 402 Layout();
(...skipping 26 matching lines...) Expand all
469 void LocationBarView::GetOmniboxPopupPositioningInfo( 429 void LocationBarView::GetOmniboxPopupPositioningInfo(
470 gfx::Point* top_left_screen_coord, 430 gfx::Point* top_left_screen_coord,
471 int* popup_width, 431 int* popup_width,
472 int* left_margin, 432 int* left_margin,
473 int* right_margin, 433 int* right_margin,
474 int top_edge_overlap) { 434 int top_edge_overlap) {
475 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); 435 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap);
476 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); 436 views::View::ConvertPointToScreen(parent(), top_left_screen_coord);
477 437
478 *popup_width = parent()->width(); 438 *popup_width = parent()->width();
479 gfx::Rect location_bar_bounds(bounds()); 439 *left_margin = x();
480 if (!ui::MaterialDesignController::IsModeMaterial()) 440 *right_margin = *popup_width - bounds().right();
481 location_bar_bounds.Inset(GetHorizontalEdgeThickness(), 0);
482 *left_margin = location_bar_bounds.x();
483 *right_margin = *popup_width - location_bar_bounds.right();
484 } 441 }
485 442
486 //////////////////////////////////////////////////////////////////////////////// 443 ////////////////////////////////////////////////////////////////////////////////
487 // LocationBarView, public LocationBar implementation: 444 // LocationBarView, public LocationBar implementation:
488 445
489 void LocationBarView::FocusLocation(bool select_all) { 446 void LocationBarView::FocusLocation(bool select_all) {
490 omnibox_view_->SetFocus(); 447 omnibox_view_->SetFocus();
491 if (select_all) 448 if (select_all)
492 omnibox_view_->SelectAll(true); 449 omnibox_view_->SelectAll(true);
493 } 450 }
(...skipping 12 matching lines...) Expand all
506 bool LocationBarView::HasFocus() const { 463 bool LocationBarView::HasFocus() const {
507 return omnibox_view_->model()->has_focus(); 464 return omnibox_view_->model()->has_focus();
508 } 465 }
509 466
510 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { 467 void LocationBarView::GetAccessibleState(ui::AXViewState* state) {
511 state->role = ui::AX_ROLE_GROUP; 468 state->role = ui::AX_ROLE_GROUP;
512 } 469 }
513 470
514 gfx::Size LocationBarView::GetPreferredSize() const { 471 gfx::Size LocationBarView::GetPreferredSize() const {
515 // Compute minimum height. 472 // Compute minimum height.
516 gfx::Size min_size; 473 gfx::Size min_size(0, GetLayoutConstant(LOCATION_BAR_HEIGHT));
517 if (ui::MaterialDesignController::IsModeMaterial() || is_popup_mode_) {
518 min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT));
519 } else {
520 min_size = border_painter_->GetMinimumSize();
521 }
522 474
523 if (!IsInitialized()) 475 if (!IsInitialized())
524 return min_size; 476 return min_size;
525 477
526 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); 478 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
527 479
528 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 480 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
529 481
530 // Compute width of omnibox-leading content. 482 // Compute width of omnibox-leading content.
531 const int edge_thickness = GetHorizontalEdgeThickness(); 483 const int edge_thickness = GetHorizontalEdgeThickness();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 LocationBarLayout::RIGHT_EDGE, item_padding, 532 LocationBarLayout::RIGHT_EDGE, item_padding,
581 item_padding - omnibox_view_->GetInsets().right()); 533 item_padding - omnibox_view_->GetInsets().right());
582 534
583 const base::string16 keyword(omnibox_view_->model()->keyword()); 535 const base::string16 keyword(omnibox_view_->model()->keyword());
584 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 536 // 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 537 // 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 538 // positioned relative to them (e.g. the "bookmark added" bubble if the user
587 // hits ctrl-d). 539 // hits ctrl-d).
588 const int bubble_horizontal_padding = 540 const int bubble_horizontal_padding =
589 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); 541 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING);
590 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(); 542 const int vertical_padding =
543 GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) +
544 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING);
Peter Kasting 2016/09/20 20:18:05 Nit: Use GetTotalVerticalPadding()
Evan Stade 2016/09/21 17:05:00 oops, done.
591 const int location_height = std::max(height() - (vertical_padding * 2), 0); 545 const int location_height = std::max(height() - (vertical_padding * 2), 0);
592 546
593 location_icon_view_->SetLabel(base::string16()); 547 location_icon_view_->SetLabel(base::string16());
594 location_icon_view_->SetBackground(false);
595 if (ShouldShowKeywordBubble()) { 548 if (ShouldShowKeywordBubble()) {
596 leading_decorations.AddDecoration(vertical_padding, location_height, true, 549 leading_decorations.AddDecoration(vertical_padding, location_height, true,
597 0, bubble_horizontal_padding, 550 0, bubble_horizontal_padding,
598 item_padding, selected_keyword_view_); 551 item_padding, selected_keyword_view_);
599 if (selected_keyword_view_->keyword() != keyword) { 552 if (selected_keyword_view_->keyword() != keyword) {
600 selected_keyword_view_->SetKeyword(keyword); 553 selected_keyword_view_->SetKeyword(keyword);
601 const TemplateURL* template_url = 554 const TemplateURL* template_url =
602 TemplateURLServiceFactory::GetForProfile(profile())-> 555 TemplateURLServiceFactory::GetForProfile(profile())->
603 GetTemplateURLForKeyword(keyword); 556 GetTemplateURLForKeyword(keyword);
604 if (template_url && 557 if (template_url &&
605 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 558 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
606 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 559 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
607 GetOmniboxIcon(template_url->GetExtensionId()); 560 GetOmniboxIcon(template_url->GetExtensionId());
608 selected_keyword_view_->SetImage(image.AsImageSkia()); 561 selected_keyword_view_->SetImage(image.AsImageSkia());
609 selected_keyword_view_->set_is_extension_icon(true);
610 } else { 562 } else {
611 selected_keyword_view_->ResetImage(); 563 selected_keyword_view_->ResetImage();
612 selected_keyword_view_->set_is_extension_icon(false);
613 } 564 }
614 } 565 }
615 } else if (ShouldShowSecurityChip()) { 566 } else if (ShouldShowSecurityChip()) {
616 location_icon_view_->SetLabel(GetSecurityText()); 567 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. 568 // The largest fraction of the omnibox that can be taken by the EV bubble.
619 const double kMaxBubbleFraction = 0.5; 569 const double kMaxBubbleFraction = 0.5;
620 leading_decorations.AddDecoration( 570 leading_decorations.AddDecoration(
621 vertical_padding, location_height, false, kMaxBubbleFraction, 571 vertical_padding, location_height, false, kMaxBubbleFraction,
622 bubble_horizontal_padding, item_padding, location_icon_view_); 572 bubble_horizontal_padding, item_padding, location_icon_view_);
623 } else { 573 } else {
624 leading_decorations.AddDecoration(vertical_padding, location_height, 574 leading_decorations.AddDecoration(vertical_padding, location_height,
625 location_icon_view_); 575 location_icon_view_);
626 } 576 }
627 577
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 x = entry_width - width; 717 x = entry_width - width;
768 location_bounds.set_width(x); 718 location_bounds.set_width(x);
769 ime_inline_autocomplete_view_->SetBounds( 719 ime_inline_autocomplete_view_->SetBounds(
770 location_bounds.right(), location_bounds.y(), 720 location_bounds.right(), location_bounds.y(),
771 std::min(width, entry_width), location_bounds.height()); 721 std::min(width, entry_width), location_bounds.height());
772 } 722 }
773 omnibox_view_->SetBoundsRect(location_bounds); 723 omnibox_view_->SetBoundsRect(location_bounds);
774 } 724 }
775 725
776 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 726 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
777 if (ui::MaterialDesignController::IsModeMaterial()) { 727 RefreshLocationIcon();
778 RefreshLocationIcon(); 728 if (!is_popup_mode_) {
779 if (!is_popup_mode_) { 729 set_background(
780 set_background(new BackgroundWith1PxBorder(GetColor(BACKGROUND), 730 new BackgroundWith1PxBorder(GetColor(BACKGROUND), kBorderColor));
781 kBorderColor));
782 }
783 } 731 }
784 } 732 }
785 733
786 void LocationBarView::Update(const WebContents* contents) { 734 void LocationBarView::Update(const WebContents* contents) {
787 RefreshContentSettingViews(); 735 RefreshContentSettingViews();
788 RefreshZoomView(); 736 RefreshZoomView();
789 RefreshPageActionViews(); 737 RefreshPageActionViews();
790 RefreshTranslateIcon(); 738 RefreshTranslateIcon();
791 RefreshSaveCreditCardIconView(); 739 RefreshSaveCreditCardIconView();
792 RefreshManagePasswordsIconView(); 740 RefreshManagePasswordsIconView();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 int LocationBarView::IncrementalMinimumWidth(views::View* view) const { 781 int LocationBarView::IncrementalMinimumWidth(views::View* view) const {
834 return view->visible() ? 782 return view->visible() ?
835 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + 783 (GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) +
836 view->GetMinimumSize().width()) : 0; 784 view->GetMinimumSize().width()) : 0;
837 } 785 }
838 786
839 int LocationBarView::GetHorizontalEdgeThickness() const { 787 int LocationBarView::GetHorizontalEdgeThickness() const {
840 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); 788 return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS);
841 } 789 }
842 790
843 int LocationBarView::GetVerticalEdgeThickness() const { 791 int LocationBarView::GetTotalVerticalPadding() const {
844 if (ui::MaterialDesignController::IsModeMaterial()) 792 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS) +
845 return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS);
846 return is_popup_mode_ ? views::NonClientFrameView::kClientEdgeThickness
847 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS);
848 }
849
850 int LocationBarView::GetVerticalEdgeThicknessWithPadding() const {
851 return GetVerticalEdgeThickness() +
852 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); 793 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING);
853 } 794 }
854 795
855 void LocationBarView::RefreshLocationIcon() { 796 void LocationBarView::RefreshLocationIcon() {
856 // |omnibox_view_| may not be ready yet if Init() has not been called. The 797 // |omnibox_view_| may not be ready yet if Init() has not been called. The
857 // icon will be set soon by OnChanged(). 798 // icon will be set soon by OnChanged().
858 if (!omnibox_view_) 799 if (!omnibox_view_)
859 return; 800 return;
860 801
861 if (ui::MaterialDesignController::IsModeMaterial()) { 802 security_state::SecurityStateModel::SecurityLevel security_level =
862 security_state::SecurityStateModel::SecurityLevel security_level = 803 GetToolbarModel()->GetSecurityLevel(false);
863 GetToolbarModel()->GetSecurityLevel(false); 804 SkColor icon_color =
864 SkColor icon_color = 805 (security_level == security_state::SecurityStateModel::NONE)
865 (security_level == security_state::SecurityStateModel::NONE) 806 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT))
866 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) 807 : GetSecureTextColor(security_level);
867 : GetSecureTextColor(security_level); 808 location_icon_view_->SetImage(gfx::CreateVectorIcon(
868 location_icon_view_->SetImage(gfx::CreateVectorIcon( 809 omnibox_view_->GetVectorIcon(), kLocationBarIconWidth, icon_color));
869 omnibox_view_->GetVectorIcon(), GetLocationIconWidth(), icon_color));
870 } else {
871 location_icon_view_->SetImage(
872 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon()));
873 }
874 } 810 }
875 811
876 bool LocationBarView::RefreshContentSettingViews() { 812 bool LocationBarView::RefreshContentSettingViews() {
877 bool visibility_changed = false; 813 bool visibility_changed = false;
878 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 814 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
879 i != content_setting_views_.end(); ++i) { 815 i != content_setting_views_.end(); ++i) {
880 const bool was_visible = (*i)->visible(); 816 const bool was_visible = (*i)->visible();
881 (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr 817 (*i)->Update(GetToolbarModel()->input_in_progress() ? nullptr
882 : GetWebContents()); 818 : GetWebContents());
883 if (was_visible != (*i)->visible()) 819 if (was_visible != (*i)->visible())
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 popup->UpdatePopupAppearance(); 1198 popup->UpdatePopupAppearance();
1263 } 1199 }
1264 1200
1265 void LocationBarView::OnFocus() { 1201 void LocationBarView::OnFocus() {
1266 omnibox_view_->SetFocus(); 1202 omnibox_view_->SetFocus();
1267 } 1203 }
1268 1204
1269 void LocationBarView::OnPaint(gfx::Canvas* canvas) { 1205 void LocationBarView::OnPaint(gfx::Canvas* canvas) {
1270 View::OnPaint(canvas); 1206 View::OnPaint(canvas);
1271 1207
1272 if (ui::MaterialDesignController::IsModeMaterial()) { 1208 if (show_focus_rect_ && omnibox_view_->HasFocus()) {
1273 if (show_focus_rect_ && omnibox_view_->HasFocus()) { 1209 SkPaint paint;
1274 SkPaint paint; 1210 paint.setAntiAlias(true);
1275 paint.setAntiAlias(true); 1211 paint.setColor(GetNativeTheme()->GetSystemColor(
1276 paint.setColor(GetNativeTheme()->GetSystemColor( 1212 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor));
1277 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor)); 1213 paint.setStyle(SkPaint::kStroke_Style);
1278 paint.setStyle(SkPaint::kStroke_Style); 1214 paint.setStrokeWidth(1);
1279 paint.setStrokeWidth(1); 1215 gfx::RectF focus_rect(GetLocalBounds());
1280 gfx::RectF focus_rect(GetLocalBounds()); 1216 focus_rect.Inset(gfx::InsetsF(0.5f));
1281 focus_rect.Inset(gfx::InsetsF(0.5f)); 1217 canvas->DrawRoundRect(focus_rect,
1282 canvas->DrawRoundRect( 1218 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 } 1219 }
1220 if (!is_popup_mode_)
1221 return; // The background and border are painted by our Background.
1288 1222
1289 // Fill the location bar background color behind the border. Parts of the 1223 // 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 1224 // 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. 1225 // the omnibox background, so we can't just blindly fill our entire bounds.
1292 gfx::Rect bounds(GetContentsBounds()); 1226 gfx::Rect bounds(GetContentsBounds());
1293 bounds.Inset(GetHorizontalEdgeThickness(), 1227 bounds.Inset(
1294 is_popup_mode_ ? 0 : GetVerticalEdgeThickness()); 1228 GetHorizontalEdgeThickness(),
1229 is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS));
1295 SkColor background_color(GetColor(BACKGROUND)); 1230 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); 1231 canvas->FillRect(bounds, background_color);
1308 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord()); 1232 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord());
1309 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); 1233 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false);
1310 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); 1234 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true);
1311 } 1235 }
1312 1236
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 //////////////////////////////////////////////////////////////////////////////// 1237 ////////////////////////////////////////////////////////////////////////////////
1332 // LocationBarView, private views::DragController implementation: 1238 // LocationBarView, private views::DragController implementation:
1333 1239
1334 void LocationBarView::WriteDragDataForView(views::View* sender, 1240 void LocationBarView::WriteDragDataForView(views::View* sender,
1335 const gfx::Point& press_pt, 1241 const gfx::Point& press_pt,
1336 OSExchangeData* data) { 1242 OSExchangeData* data) {
1337 DCHECK_NE(GetDragOperationsForView(sender, press_pt), 1243 DCHECK_NE(GetDragOperationsForView(sender, press_pt),
1338 ui::DragDropTypes::DRAG_NONE); 1244 ui::DragDropTypes::DRAG_NONE);
1339 1245
1340 WebContents* web_contents = GetWebContents(); 1246 WebContents* web_contents = GetWebContents();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 // LocationBarView, private TemplateURLServiceObserver implementation: 1303 // LocationBarView, private TemplateURLServiceObserver implementation:
1398 1304
1399 void LocationBarView::OnTemplateURLServiceChanged() { 1305 void LocationBarView::OnTemplateURLServiceChanged() {
1400 template_url_service_->RemoveObserver(this); 1306 template_url_service_->RemoveObserver(this);
1401 template_url_service_ = nullptr; 1307 template_url_service_ = nullptr;
1402 // If the browser is no longer active, let's not show the info bubble, as this 1308 // 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. 1309 // would make the browser the active window again.
1404 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1310 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1405 ShowFirstRunBubble(); 1311 ShowFirstRunBubble();
1406 } 1312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698