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

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

Issue 10957010: alternate ntp: focus border of omnibox in ntp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed david's comments Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "ui/base/accessibility/accessible_view_state.h" 66 #include "ui/base/accessibility/accessible_view_state.h"
67 #include "ui/base/dragdrop/drag_drop_types.h" 67 #include "ui/base/dragdrop/drag_drop_types.h"
68 #include "ui/base/events/event.h" 68 #include "ui/base/events/event.h"
69 #include "ui/base/l10n/l10n_util.h" 69 #include "ui/base/l10n/l10n_util.h"
70 #include "ui/base/layout.h" 70 #include "ui/base/layout.h"
71 #include "ui/base/resource/resource_bundle.h" 71 #include "ui/base/resource/resource_bundle.h"
72 #include "ui/base/theme_provider.h" 72 #include "ui/base/theme_provider.h"
73 #include "ui/gfx/canvas.h" 73 #include "ui/gfx/canvas.h"
74 #include "ui/gfx/color_utils.h" 74 #include "ui/gfx/color_utils.h"
75 #include "ui/gfx/image/image.h" 75 #include "ui/gfx/image/image.h"
76 #include "ui/gfx/image/image_skia_operations.h"
76 #include "ui/gfx/skia_util.h" 77 #include "ui/gfx/skia_util.h"
77 #include "ui/views/border.h" 78 #include "ui/views/border.h"
78 #include "ui/views/button_drag_utils.h" 79 #include "ui/views/button_drag_utils.h"
79 #include "ui/views/controls/label.h" 80 #include "ui/views/controls/label.h"
80 #include "ui/views/widget/widget.h" 81 #include "ui/views/widget/widget.h"
81 82
82 #if defined(OS_WIN) && !defined(USE_AURA) 83 #if defined(OS_WIN) && !defined(USE_AURA)
83 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" 84 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h"
84 #endif 85 #endif
85 86
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 web_intents_button_view_(NULL), 211 web_intents_button_view_(NULL),
211 action_box_button_view_(NULL), 212 action_box_button_view_(NULL),
212 mode_(mode), 213 mode_(mode),
213 show_focus_rect_(false), 214 show_focus_rect_(false),
214 template_url_service_(NULL), 215 template_url_service_(NULL),
215 animation_offset_(0), 216 animation_offset_(0),
216 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { 217 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) {
217 set_id(VIEW_ID_LOCATION_BAR); 218 set_id(VIEW_ID_LOCATION_BAR);
218 219
219 if (mode_ == NORMAL) { 220 if (mode_ == NORMAL) {
220 painter_.reset( 221 background_painter_.reset(
221 views::Painter::CreateImagePainter( 222 views::Painter::CreateImagePainter(
222 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( 223 *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
223 IDR_LOCATION_BAR_BORDER).ToImageSkia(), 224 IDR_LOCATION_BAR_BORDER).ToImageSkia(),
224 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, 225 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth,
225 kBorderRoundCornerHeight, kBorderRoundCornerWidth), 226 kBorderRoundCornerHeight, kBorderRoundCornerWidth),
226 true)); 227 true));
227 } 228 }
228 229
229 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, 230 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled,
230 profile_->GetPrefs(), this); 231 profile_->GetPrefs(), this);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 const chrome::search::Mode& new_mode) { 417 const chrome::search::Mode& new_mode) {
417 #if defined(USE_AURA) 418 #if defined(USE_AURA)
418 if (new_mode.animate && old_mode.is_ntp() && new_mode.is_search()) { 419 if (new_mode.animate && old_mode.is_ntp() && new_mode.is_search()) {
419 // Fade in so the icons don't pop. 420 // Fade in so the icons don't pop.
420 StartFadeAnimation(); 421 StartFadeAnimation();
421 } else { 422 } else {
422 // Cancel any pending animations; switch to the final state immediately. 423 // Cancel any pending animations; switch to the final state immediately.
423 StopFadeAnimation(); 424 StopFadeAnimation();
424 } 425 }
425 #endif 426 #endif
427
428 // Focus border may have changed, schedule paint to redraw.
429 SchedulePaint();
426 } 430 }
427 431
428 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { 432 void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
429 RefreshContentSettingViews(); 433 RefreshContentSettingViews();
430 ZoomBubbleView::CloseBubble(); 434 ZoomBubbleView::CloseBubble();
431 RefreshZoomView(); 435 RefreshZoomView();
432 RefreshPageActionViews(); 436 RefreshPageActionViews();
433 web_intents_button_view_->Update(GetTabContents()); 437 web_intents_button_view_->Update(GetTabContents());
434 open_pdf_in_reader_view_->Update( 438 open_pdf_in_reader_view_->Update(
435 model_->input_in_progress() ? NULL : GetTabContents()); 439 model_->input_in_progress() ? NULL : GetTabContents());
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 int location_y = kVerticalEdgeThickness; 663 int location_y = kVerticalEdgeThickness;
660 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 664 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
661 // to position our child views in this case, because other things may be 665 // to position our child views in this case, because other things may be
662 // positioned relative to them (e.g. the "bookmark added" bubble if the user 666 // positioned relative to them (e.g. the "bookmark added" bubble if the user
663 // hits ctrl-d). 667 // hits ctrl-d).
664 int location_height = GetInternalHeight(false); 668 int location_height = GetInternalHeight(false);
665 669
666 // In NTP mode, hide all location bar decorations. 670 // In NTP mode, hide all location bar decorations.
667 if (search_model_ && search_model_->mode().is_ntp()) { 671 if (search_model_ && search_model_->mode().is_ntp()) {
668 gfx::Rect location_bounds(0, location_y, width(), location_height); 672 gfx::Rect location_bounds(0, location_y, width(), location_height);
673 // The location bar border, when drawn, has colored edges that need to be
674 // inset, so that these edges won't be clipped by |location_entry_view_|.
675 // |location_y| and |location_height| already include insets of top and
676 // bottom edges, so we only need to inset for left and right edges here.
677 location_bounds.Inset(kNormalHorizontalEdgeThickness, 0);
669 location_entry_view_->SetBoundsRect(location_bounds); 678 location_entry_view_->SetBoundsRect(location_bounds);
670 for (int i = 0; i < child_count(); ++i) 679 for (int i = 0; i < child_count(); ++i)
671 if (child_at(i) != location_entry_view_) 680 if (child_at(i) != location_entry_view_)
672 child_at(i)->SetVisible(false); 681 child_at(i)->SetVisible(false);
673 return; 682 return;
674 } 683 }
675 684
676 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the 685 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the
677 // omnibox' parent, so there isn't any edge to account for at all. 686 // omnibox' parent, so there isn't any edge to account for at all.
678 const int kEdgeThickness = (mode_ == NORMAL) ? 687 const int kEdgeThickness = (mode_ == NORMAL) ?
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 location_bounds.height()); 953 location_bounds.height());
945 } 954 }
946 } 955 }
947 956
948 location_entry_view_->SetBoundsRect(location_bounds); 957 location_entry_view_->SetBoundsRect(location_bounds);
949 } 958 }
950 959
951 void LocationBarView::OnPaint(gfx::Canvas* canvas) { 960 void LocationBarView::OnPaint(gfx::Canvas* canvas) {
952 View::OnPaint(canvas); 961 View::OnPaint(canvas);
953 962
954 if (painter_.get()) { 963 // If search mode is |NTP|, paint the background color of NTP page first;
955 painter_->Paint(canvas, size()); 964 // otherwise, there will be a white outline around the location bar border.
965 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp();
966 if (is_search_ntp)
967 canvas->DrawColor(chrome::search::kNTPBackgroundColor);
968
969 if (background_painter_.get()) {
970 background_painter_->Paint(canvas, size());
956 } else if (mode_ == POPUP) { 971 } else if (mode_ == POPUP) {
957 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed( 972 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed(
958 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); 973 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height());
959 } 974 }
960 // When used in the app launcher, don't draw a border, the LocationBarView has 975 // When used in the app launcher, don't draw a border, the LocationBarView has
961 // its own views::Border. 976 // its own views::Border.
962 977
963 // Draw the background color so that the graphical elements at the edges 978 // Draw the background color so that the graphical elements at the edges
964 // appear over the correct color. (The edit draws its own background, so this 979 // appear over the correct color. (The edit draws its own background, so this
965 // isn't important for that.) 980 // isn't important for that.)
(...skipping 16 matching lines...) Expand all
982 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, 997 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius,
983 radius, paint); 998 radius, paint);
984 if (action_box_button_view_) 999 if (action_box_button_view_)
985 PaintActionBoxBackground(canvas, bounds); 1000 PaintActionBoxBackground(canvas, bounds);
986 } else { 1001 } else {
987 canvas->FillRect(bounds, color); 1002 canvas->FillRect(bounds, color);
988 } 1003 }
989 1004
990 // If |show_focus_rect_| is false but search mode is |NTP|, we still show 1005 // If |show_focus_rect_| is false but search mode is |NTP|, we still show
991 // focus rect. 1006 // focus rect.
992 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp();
993 bool show_focus_rect = show_focus_rect_ || is_search_ntp; 1007 bool show_focus_rect = show_focus_rect_ || is_search_ntp;
994 if (show_focus_rect && HasFocus()) { 1008 if (show_focus_rect && HasFocus()) {
1009 if (is_search_ntp) {
1010 // Load search focus border mask image if not already loaded.
1011 if (!search_focus_painter_.get()) {
1012 search_focus_painter_.reset(
1013 views::Painter::CreateImagePainter(
1014 *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
1015 IDR_LOCATION_BAR_SEARCH_FOCUS_BORDER_MASK).ToImageSkia(),
1016 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth,
1017 kBorderRoundCornerHeight, kBorderRoundCornerWidth),
1018 true));
1019 if (!search_focus_painter_.get())
dhollowa 2012/09/20 19:05:11 This should be a DCHECK. No return.
kuan 2012/09/20 19:47:21 Done.
1020 return;
1021 }
1022
1023 // On first canvas, draw rounded rect with system highlight color.
1024 gfx::Canvas border_canvas(size(), canvas->scale_factor(), false);
1025 SkPaint paint;
1026 paint.setColor(ui::NativeTheme::instance()->GetSystemColor(
1027 ui::NativeTheme::kColorId_FocusedBorderColor));
1028 paint.setStyle(SkPaint::kFill_Style);
1029 paint.setAntiAlias(true);
1030 border_canvas.DrawRoundRect(GetLocalBounds(), kBorderCornerRadius, paint);
1031
1032 // On second canvas, draw the mask image.
1033 gfx::Canvas mask_canvas(size(), canvas->scale_factor(), false);
1034 search_focus_painter_->Paint(&mask_canvas, size());
1035
1036 // Create a masked image from the 2 canvases, and draw the final image
1037 // on the destination canvas.
1038 gfx::ImageSkia focuse_image =
dhollowa 2012/09/20 19:05:11 nit: s/focuse_image/focus_image/
kuan 2012/09/20 19:47:21 Done.
1039 gfx::ImageSkiaOperations::CreateMaskedImage(
1040 gfx::ImageSkia(border_canvas.ExtractImageRep()),
1041 gfx::ImageSkia(mask_canvas.ExtractImageRep()));
1042 canvas->DrawImageInt(focuse_image, 0, 0);
1043 return;
1044 }
1045
995 gfx::Rect r = location_entry_view_->bounds(); 1046 gfx::Rect r = location_entry_view_->bounds();
996
997 // TODO(jamescook): Is this still needed? 1047 // TODO(jamescook): Is this still needed?
998 #if defined(OS_WIN) 1048 #if defined(OS_WIN)
999 r.Inset(-1, -1); 1049 r.Inset(-1, -1);
1000 #else 1050 #else
1001 r.Inset(-1, 0); 1051 r.Inset(-1, 0);
1002 #endif 1052 #endif
1003 canvas->DrawFocusRect(r); 1053 canvas->DrawFocusRect(r);
1004 } 1054 }
1005 } 1055 }
1006 1056
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 } 1630 }
1581 1631
1582 void LocationBarView::CleanupFadeAnimation() { 1632 void LocationBarView::CleanupFadeAnimation() {
1583 // Since we're no longer animating we don't need our layer. 1633 // Since we're no longer animating we don't need our layer.
1584 SetPaintToLayer(false); 1634 SetPaintToLayer(false);
1585 // Bubble labels don't need a transparent background anymore. 1635 // Bubble labels don't need a transparent background anymore.
1586 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1636 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1587 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1637 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1588 } 1638 }
1589 #endif // USE_AURA 1639 #endif // USE_AURA
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698