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

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: rebased, merged conflicts 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "ui/base/accessibility/accessible_view_state.h" 67 #include "ui/base/accessibility/accessible_view_state.h"
68 #include "ui/base/dragdrop/drag_drop_types.h" 68 #include "ui/base/dragdrop/drag_drop_types.h"
69 #include "ui/base/events/event.h" 69 #include "ui/base/events/event.h"
70 #include "ui/base/l10n/l10n_util.h" 70 #include "ui/base/l10n/l10n_util.h"
71 #include "ui/base/layout.h" 71 #include "ui/base/layout.h"
72 #include "ui/base/resource/resource_bundle.h" 72 #include "ui/base/resource/resource_bundle.h"
73 #include "ui/base/theme_provider.h" 73 #include "ui/base/theme_provider.h"
74 #include "ui/gfx/canvas.h" 74 #include "ui/gfx/canvas.h"
75 #include "ui/gfx/color_utils.h" 75 #include "ui/gfx/color_utils.h"
76 #include "ui/gfx/image/image.h" 76 #include "ui/gfx/image/image.h"
77 #include "ui/gfx/image/image_skia_operations.h"
77 #include "ui/gfx/skia_util.h" 78 #include "ui/gfx/skia_util.h"
78 #include "ui/views/border.h" 79 #include "ui/views/border.h"
79 #include "ui/views/button_drag_utils.h" 80 #include "ui/views/button_drag_utils.h"
80 #include "ui/views/controls/label.h" 81 #include "ui/views/controls/label.h"
81 #include "ui/views/widget/widget.h" 82 #include "ui/views/widget/widget.h"
82 83
83 #if defined(OS_WIN) && !defined(USE_AURA) 84 #if defined(OS_WIN) && !defined(USE_AURA)
84 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" 85 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h"
85 #endif 86 #endif
86 87
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 web_intents_button_view_(NULL), 214 web_intents_button_view_(NULL),
214 action_box_button_view_(NULL), 215 action_box_button_view_(NULL),
215 mode_(mode), 216 mode_(mode),
216 show_focus_rect_(false), 217 show_focus_rect_(false),
217 template_url_service_(NULL), 218 template_url_service_(NULL),
218 animation_offset_(0), 219 animation_offset_(0),
219 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { 220 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) {
220 set_id(VIEW_ID_LOCATION_BAR); 221 set_id(VIEW_ID_LOCATION_BAR);
221 222
222 if (mode_ == NORMAL) { 223 if (mode_ == NORMAL) {
223 painter_.reset( 224 background_painter_.reset(
224 views::Painter::CreateImagePainter( 225 views::Painter::CreateImagePainter(
225 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( 226 *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
226 IDR_LOCATION_BAR_BORDER).ToImageSkia(), 227 IDR_LOCATION_BAR_BORDER).ToImageSkia(),
227 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, 228 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth,
228 kBorderRoundCornerHeight, kBorderRoundCornerWidth), 229 kBorderRoundCornerHeight, kBorderRoundCornerWidth),
229 true)); 230 true));
230 } 231 }
231 232
232 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, 233 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled,
233 profile_->GetPrefs(), this); 234 profile_->GetPrefs(), this);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 const chrome::search::Mode& new_mode) { 423 const chrome::search::Mode& new_mode) {
423 #if defined(USE_AURA) 424 #if defined(USE_AURA)
424 if (new_mode.animate && old_mode.is_ntp() && new_mode.is_search()) { 425 if (new_mode.animate && old_mode.is_ntp() && new_mode.is_search()) {
425 // Fade in so the icons don't pop. 426 // Fade in so the icons don't pop.
426 StartFadeAnimation(); 427 StartFadeAnimation();
427 } else { 428 } else {
428 // Cancel any pending animations; switch to the final state immediately. 429 // Cancel any pending animations; switch to the final state immediately.
429 StopFadeAnimation(); 430 StopFadeAnimation();
430 } 431 }
431 #endif 432 #endif
433
434 // Focus border changes when the search mode transitions to or from |NTP|,
435 // schedule paint to redraw.
436 if (old_mode.is_ntp() || new_mode.is_ntp())
437 SchedulePaint();
432 } 438 }
433 439
434 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { 440 void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
435 RefreshContentSettingViews(); 441 RefreshContentSettingViews();
436 ZoomBubbleView::CloseBubble(); 442 ZoomBubbleView::CloseBubble();
437 RefreshZoomView(); 443 RefreshZoomView();
438 RefreshPageActionViews(); 444 RefreshPageActionViews();
439 web_intents_button_view_->Update(GetTabContents()); 445 web_intents_button_view_->Update(GetTabContents());
440 open_pdf_in_reader_view_->Update( 446 open_pdf_in_reader_view_->Update(
441 model_->input_in_progress() ? NULL : GetTabContents()); 447 model_->input_in_progress() ? NULL : GetTabContents());
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 int location_y = kVerticalEdgeThickness; 671 int location_y = kVerticalEdgeThickness;
666 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 672 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
667 // to position our child views in this case, because other things may be 673 // to position our child views in this case, because other things may be
668 // positioned relative to them (e.g. the "bookmark added" bubble if the user 674 // positioned relative to them (e.g. the "bookmark added" bubble if the user
669 // hits ctrl-d). 675 // hits ctrl-d).
670 int location_height = GetInternalHeight(false); 676 int location_height = GetInternalHeight(false);
671 677
672 // In NTP mode, hide all location bar decorations. 678 // In NTP mode, hide all location bar decorations.
673 if (search_model_ && search_model_->mode().is_ntp()) { 679 if (search_model_ && search_model_->mode().is_ntp()) {
674 gfx::Rect location_bounds(0, location_y, width(), location_height); 680 gfx::Rect location_bounds(0, location_y, width(), location_height);
681 // The location bar border, when drawn, has colored edges that need to be
682 // inset, so that these edges won't be clipped by |location_entry_view_|.
683 // |location_y| and |location_height| already include insets of top and
684 // bottom edges, so we only need to inset for left and right edges here.
685 location_bounds.Inset(kNormalHorizontalEdgeThickness, 0);
675 location_entry_view_->SetBoundsRect(location_bounds); 686 location_entry_view_->SetBoundsRect(location_bounds);
676 for (int i = 0; i < child_count(); ++i) 687 for (int i = 0; i < child_count(); ++i)
677 if (child_at(i) != location_entry_view_) 688 if (child_at(i) != location_entry_view_)
678 child_at(i)->SetVisible(false); 689 child_at(i)->SetVisible(false);
679 return; 690 return;
680 } 691 }
681 692
682 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the 693 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the
683 // omnibox' parent, so there isn't any edge to account for at all. 694 // omnibox' parent, so there isn't any edge to account for at all.
684 const int kEdgeThickness = (mode_ == NORMAL) ? 695 const int kEdgeThickness = (mode_ == NORMAL) ?
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 location_bounds.height()); 961 location_bounds.height());
951 } 962 }
952 } 963 }
953 964
954 location_entry_view_->SetBoundsRect(location_bounds); 965 location_entry_view_->SetBoundsRect(location_bounds);
955 } 966 }
956 967
957 void LocationBarView::OnPaint(gfx::Canvas* canvas) { 968 void LocationBarView::OnPaint(gfx::Canvas* canvas) {
958 View::OnPaint(canvas); 969 View::OnPaint(canvas);
959 970
960 if (painter_.get()) { 971 // If search mode is |NTP|, paint the background color of NTP page first;
961 painter_->Paint(canvas, size()); 972 // otherwise, there will be a white outline around the location bar border.
973 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp();
974 if (is_search_ntp)
975 canvas->DrawColor(chrome::search::kNTPBackgroundColor);
976
977 if (background_painter_.get()) {
978 background_painter_->Paint(canvas, size());
962 } else if (mode_ == POPUP) { 979 } else if (mode_ == POPUP) {
963 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed( 980 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed(
964 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); 981 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height());
965 } 982 }
966 // When used in the app launcher, don't draw a border, the LocationBarView has 983 // When used in the app launcher, don't draw a border, the LocationBarView has
967 // its own views::Border. 984 // its own views::Border.
968 985
969 // Draw the background color so that the graphical elements at the edges 986 // Draw the background color so that the graphical elements at the edges
970 // appear over the correct color. (The edit draws its own background, so this 987 // appear over the correct color. (The edit draws its own background, so this
971 // isn't important for that.) 988 // isn't important for that.)
(...skipping 17 matching lines...) Expand all
989 radius, paint); 1006 radius, paint);
990 if (action_box_button_view_) 1007 if (action_box_button_view_)
991 PaintActionBoxBackground(canvas, bounds); 1008 PaintActionBoxBackground(canvas, bounds);
992 PaintPageActionBackgrounds(canvas); 1009 PaintPageActionBackgrounds(canvas);
993 } else { 1010 } else {
994 canvas->FillRect(bounds, color); 1011 canvas->FillRect(bounds, color);
995 } 1012 }
996 1013
997 // If |show_focus_rect_| is false but search mode is |NTP|, we still show 1014 // If |show_focus_rect_| is false but search mode is |NTP|, we still show
998 // focus rect. 1015 // focus rect.
999 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp();
1000 bool show_focus_rect = show_focus_rect_ || is_search_ntp; 1016 bool show_focus_rect = show_focus_rect_ || is_search_ntp;
1001 if (show_focus_rect && HasFocus()) { 1017 if (show_focus_rect && HasFocus()) {
1018 if (is_search_ntp) {
1019 PaintSearchNTPFocusBorder(canvas);
1020 return;
1021 }
1022
1002 gfx::Rect r = location_entry_view_->bounds(); 1023 gfx::Rect r = location_entry_view_->bounds();
1003
1004 // TODO(jamescook): Is this still needed? 1024 // TODO(jamescook): Is this still needed?
1005 #if defined(OS_WIN) 1025 #if defined(OS_WIN)
1006 r.Inset(-1, -1); 1026 r.Inset(-1, -1);
1007 #else 1027 #else
1008 r.Inset(-1, 0); 1028 r.Inset(-1, 0);
1009 #endif 1029 #endif
1010 canvas->DrawFocusRect(r); 1030 canvas->DrawFocusRect(r);
1011 } 1031 }
1012 } 1032 }
1013 1033
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 int total_height = 1592 int total_height =
1573 use_preferred_size ? GetPreferredSize().height() : height(); 1593 use_preferred_size ? GetPreferredSize().height() : height();
1574 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); 1594 return std::max(total_height - (kVerticalEdgeThickness * 2), 0);
1575 } 1595 }
1576 1596
1577 bool LocationBarView::HasValidSuggestText() const { 1597 bool LocationBarView::HasValidSuggestText() const {
1578 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1598 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1579 !suggested_text_view_->text().empty(); 1599 !suggested_text_view_->text().empty();
1580 } 1600 }
1581 1601
1602 void LocationBarView::PaintSearchNTPFocusBorder(gfx::Canvas* canvas) {
1603 // Load search focus border mask image if not already loaded.
1604 if (!search_focus_painter_.get()) {
1605 search_focus_painter_.reset(
1606 views::Painter::CreateImagePainter(
1607 *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
1608 IDR_LOCATION_BAR_SEARCH_FOCUS_BORDER_MASK).ToImageSkia(),
1609 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth,
1610 kBorderRoundCornerHeight, kBorderRoundCornerWidth),
1611 true));
1612 DCHECK(search_focus_painter_.get());
1613 }
1614
1615 // On first canvas, draw rounded rect with system highlight color.
1616 gfx::Canvas border_canvas(size(), canvas->scale_factor(), false);
1617 SkPaint paint;
1618 paint.setColor(ui::NativeTheme::instance()->GetSystemColor(
1619 ui::NativeTheme::kColorId_FocusedBorderColor));
1620 paint.setStyle(SkPaint::kFill_Style);
1621 paint.setAntiAlias(true);
1622 border_canvas.DrawRoundRect(GetLocalBounds(), kBorderCornerRadius, paint);
1623
1624 // On second canvas, draw the mask image.
1625 gfx::Canvas mask_canvas(size(), canvas->scale_factor(), false);
1626 search_focus_painter_->Paint(&mask_canvas, size());
1627
1628 // Create a masked image from the 2 canvases, and draw the final image
1629 // on the destination canvas.
1630 gfx::ImageSkia focus_image =
1631 gfx::ImageSkiaOperations::CreateMaskedImage(
1632 gfx::ImageSkia(border_canvas.ExtractImageRep()),
1633 gfx::ImageSkia(mask_canvas.ExtractImageRep()));
1634 canvas->DrawImageInt(focus_image, 0, 0);
1635 }
1636
1582 #if defined(USE_AURA) 1637 #if defined(USE_AURA)
1583 void LocationBarView::StartFadeAnimation() { 1638 void LocationBarView::StartFadeAnimation() {
1584 // We do an opacity animation on this view, so it needs a layer. 1639 // We do an opacity animation on this view, so it needs a layer.
1585 SetPaintToLayer(true); 1640 SetPaintToLayer(true);
1586 layer()->SetFillsBoundsOpaquely(false); 1641 layer()->SetFillsBoundsOpaquely(false);
1587 1642
1588 // Sub-pixel text rendering doesn't work properly on top of non-opaque 1643 // Sub-pixel text rendering doesn't work properly on top of non-opaque
1589 // layers, so disable it by setting a transparent background color on the 1644 // layers, so disable it by setting a transparent background color on the
1590 // bubble labels. 1645 // bubble labels.
1591 const SkColor kTransparentWhite = SkColorSetARGB(128, 255, 255, 255); 1646 const SkColor kTransparentWhite = SkColorSetARGB(128, 255, 255, 255);
(...skipping 20 matching lines...) Expand all
1612 } 1667 }
1613 1668
1614 void LocationBarView::CleanupFadeAnimation() { 1669 void LocationBarView::CleanupFadeAnimation() {
1615 // Since we're no longer animating we don't need our layer. 1670 // Since we're no longer animating we don't need our layer.
1616 SetPaintToLayer(false); 1671 SetPaintToLayer(false);
1617 // Bubble labels don't need a transparent background anymore. 1672 // Bubble labels don't need a transparent background anymore.
1618 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1673 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1619 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1674 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1620 } 1675 }
1621 #endif // USE_AURA 1676 #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