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

Side by Side Diff: chrome/browser/ui/views/find_bar_view.cc

Issue 135863002: Reland Merge NativeTextfieldViews into views::Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle Ctrl-Shift-Delete and Backspace on Linux, like on ChromeOS. Created 6 years, 11 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
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/find_bar_view.h" 5 #include "chrome/browser/ui/views/find_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/ui/views/frame/browser_view.h" 21 #include "chrome/browser/ui/views/frame/browser_view.h"
22 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
24 #include "grit/ui_resources.h" 24 #include "grit/ui_resources.h"
25 #include "third_party/skia/include/effects/SkGradientShader.h" 25 #include "third_party/skia/include/effects/SkGradientShader.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/base/theme_provider.h" 28 #include "ui/base/theme_provider.h"
29 #include "ui/events/event.h" 29 #include "ui/events/event.h"
30 #include "ui/gfx/canvas.h" 30 #include "ui/gfx/canvas.h"
31 #include "ui/views/border.h"
31 #include "ui/views/controls/button/image_button.h" 32 #include "ui/views/controls/button/image_button.h"
32 #include "ui/views/controls/label.h" 33 #include "ui/views/controls/label.h"
33 #include "ui/views/controls/textfield/textfield.h" 34 #include "ui/views/controls/textfield/textfield.h"
34 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
35 36
36 // The amount of whitespace to have before the find button. 37 // The amount of whitespace to have before the find button.
37 static const int kWhiteSpaceAfterMatchCountLabel = 1; 38 static const int kWhiteSpaceAfterMatchCountLabel = 1;
38 39
39 // The margins around the search field and the close button. 40 // The margins around the search field and the close button.
40 static const int kMarginLeftOfCloseButton = 3; 41 static const int kMarginLeftOfCloseButton = 3;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 text_box_background_(NULL), 79 text_box_background_(NULL),
79 text_box_background_left_(NULL) { 80 text_box_background_left_(NULL) {
80 set_id(VIEW_ID_FIND_IN_PAGE); 81 set_id(VIEW_ID_FIND_IN_PAGE);
81 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 82 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
82 83
83 find_text_ = new views::Textfield; 84 find_text_ = new views::Textfield;
84 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); 85 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
85 find_text_->set_default_width_in_chars(kDefaultCharWidth); 86 find_text_->set_default_width_in_chars(kDefaultCharWidth);
86 find_text_->SetController(this); 87 find_text_->SetController(this);
87 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); 88 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND));
89 // The find bar textfield has a background image instead of a border.
90 const gfx::Insets insets = find_text_->GetInsets();
91 find_text_->set_border(
92 views::Border::CreateEmptyBorder(insets.top(), 0, insets.bottom(), 2));
88 93
89 AddChildView(find_text_); 94 AddChildView(find_text_);
90 95
91 match_count_text_ = new views::Label(); 96 match_count_text_ = new views::Label();
92 AddChildView(match_count_text_); 97 AddChildView(match_count_text_);
93 98
94 // Create a focus forwarder view which sends focus to find_text_. 99 // Create a focus forwarder view which sends focus to find_text_.
95 focus_forwarder_view_ = new FocusForwarderView(find_text_); 100 focus_forwarder_view_ = new FocusForwarderView(find_text_);
96 AddChildView(focus_forwarder_view_); 101 AddChildView(focus_forwarder_view_);
97 102
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // The focus forwarder view is a hidden view that should cover the area 337 // The focus forwarder view is a hidden view that should cover the area
333 // between the find text box and the find button so that when the user clicks 338 // between the find text box and the find button so that when the user clicks
334 // in that area we focus on the find text box. 339 // in that area we focus on the find text box.
335 int find_text_edge = find_text_->x() + find_text_->width(); 340 int find_text_edge = find_text_->x() + find_text_->width();
336 focus_forwarder_view_->SetBounds( 341 focus_forwarder_view_->SetBounds(
337 find_text_edge, find_previous_button_->y(), 342 find_text_edge, find_previous_button_->y(),
338 find_previous_button_->x() - find_text_edge, 343 find_previous_button_->x() - find_text_edge,
339 find_previous_button_->height()); 344 find_previous_button_->height());
340 } 345 }
341 346
342 void FindBarView::ViewHierarchyChanged(
343 const ViewHierarchyChangedDetails& details) {
344 if (details.is_add && details.child == this) {
345 find_text_->SetHorizontalMargins(0, 2); // Left and Right margins.
346 find_text_->RemoveBorder(); // We draw our own border (a background image).
347 }
348 }
349
350 gfx::Size FindBarView::GetPreferredSize() { 347 gfx::Size FindBarView::GetPreferredSize() {
351 gfx::Size prefsize = find_text_->GetPreferredSize(); 348 gfx::Size prefsize = find_text_->GetPreferredSize();
352 prefsize.set_height(preferred_height_); 349 prefsize.set_height(preferred_height_);
353 350
354 // Add up all the preferred sizes and margins of the rest of the controls. 351 // Add up all the preferred sizes and margins of the rest of the controls.
355 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + 352 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton +
356 kMarginLeftOfFindTextfield, 353 kMarginLeftOfFindTextfield,
357 0); 354 0);
358 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); 355 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0);
359 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); 356 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 496
500 void FindBarView::OnThemeChanged() { 497 void FindBarView::OnThemeChanged() {
501 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 498 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
502 if (GetThemeProvider()) { 499 if (GetThemeProvider()) {
503 close_button_->SetBackground( 500 close_button_->SetBackground(
504 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), 501 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT),
505 rb.GetImageSkiaNamed(IDR_CLOSE_1), 502 rb.GetImageSkiaNamed(IDR_CLOSE_1),
506 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); 503 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK));
507 } 504 }
508 } 505 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/find_bar_view.h ('k') | chrome/browser/ui/views/location_bar/location_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698