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

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

Issue 8221027: Make views::Label and views::Link auto-color themselves to be readable over their background colo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 find_text_ = new SearchTextfieldView(); 82 find_text_ = new SearchTextfieldView();
83 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); 83 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
84 find_text_->SetFont(rb.GetFont(ResourceBundle::BaseFont)); 84 find_text_->SetFont(rb.GetFont(ResourceBundle::BaseFont));
85 find_text_->set_default_width_in_chars(kDefaultCharWidth); 85 find_text_->set_default_width_in_chars(kDefaultCharWidth);
86 find_text_->SetController(this); 86 find_text_->SetController(this);
87 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); 87 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND));
88 AddChildView(find_text_); 88 AddChildView(find_text_);
89 89
90 match_count_text_ = new views::Label(); 90 match_count_text_ = new views::Label();
91 match_count_text_->SetFont(rb.GetFont(ResourceBundle::BaseFont)); 91 match_count_text_->SetFont(rb.GetFont(ResourceBundle::BaseFont));
92 match_count_text_->SetColor(kTextColorMatchCount);
93 match_count_text_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); 92 match_count_text_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
94 AddChildView(match_count_text_); 93 AddChildView(match_count_text_);
95 94
96 // Create a focus forwarder view which sends focus to find_text_. 95 // Create a focus forwarder view which sends focus to find_text_.
97 focus_forwarder_view_ = new FocusForwarderView(find_text_); 96 focus_forwarder_view_ = new FocusForwarderView(find_text_);
98 AddChildView(focus_forwarder_view_); 97 AddChildView(focus_forwarder_view_);
99 98
100 find_previous_button_ = new views::ImageButton(this); 99 find_previous_button_ = new views::ImageButton(this);
101 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); 100 find_previous_button_->set_tag(FIND_PREVIOUS_TAG);
102 find_previous_button_->set_focusable(true); 101 find_previous_button_->set_focusable(true);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; 175 result.number_of_matches() != -1 && result.active_match_ordinal() != -1;
177 176
178 // http://crbug.com/34970: some IMEs get confused if we change the text 177 // http://crbug.com/34970: some IMEs get confused if we change the text
179 // composed by them. To avoid this problem, we should check the IME status and 178 // composed by them. To avoid this problem, we should check the IME status and
180 // update the text only when the IME is not composing text. 179 // update the text only when the IME is not composing text.
181 if (find_text_->text() != find_text && !find_text_->IsIMEComposing()) { 180 if (find_text_->text() != find_text && !find_text_->IsIMEComposing()) {
182 find_text_->SetText(find_text); 181 find_text_->SetText(find_text);
183 find_text_->SelectAll(); 182 find_text_->SelectAll();
184 } 183 }
185 184
186 if (!find_text.empty() && have_valid_range) { 185 if (find_text.empty() || !have_valid_range) {
187 match_count_text_->SetText(
188 l10n_util::GetStringFUTF16(IDS_FIND_IN_PAGE_COUNT,
189 base::IntToString16(result.active_match_ordinal()),
190 base::IntToString16(result.number_of_matches())));
191
192 UpdateMatchCountAppearance(result.number_of_matches() == 0 &&
193 result.final_update());
194 } else {
195 // If there was no text entered, we don't show anything in the result count 186 // If there was no text entered, we don't show anything in the result count
196 // area. 187 // area.
197 match_count_text_->SetText(string16()); 188 ClearMatchCount();
189 return;
190 }
198 191
199 UpdateMatchCountAppearance(false); 192 match_count_text_->SetText(l10n_util::GetStringFUTF16(IDS_FIND_IN_PAGE_COUNT,
200 } 193 base::IntToString16(result.active_match_ordinal()),
194 base::IntToString16(result.number_of_matches())));
195
196 UpdateMatchCountAppearance(result.number_of_matches() == 0 &&
197 result.final_update());
201 198
202 // The match_count label may have increased/decreased in size so we need to 199 // The match_count label may have increased/decreased in size so we need to
203 // do a layout and repaint the dialog so that the find text field doesn't 200 // do a layout and repaint the dialog so that the find text field doesn't
204 // partially overlap the match-count label when it increases on no matches. 201 // partially overlap the match-count label when it increases on no matches.
205 Layout(); 202 Layout();
206 SchedulePaint(); 203 SchedulePaint();
207 } 204 }
208 205
209 void FindBarView::ClearMatchCount() { 206 void FindBarView::ClearMatchCount() {
210 match_count_text_->SetText(string16()); 207 match_count_text_->SetText(string16());
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 } 444 }
448 } 445 }
449 446
450 return false; 447 return false;
451 } 448 }
452 449
453 void FindBarView::UpdateMatchCountAppearance(bool no_match) { 450 void FindBarView::UpdateMatchCountAppearance(bool no_match) {
454 if (no_match) { 451 if (no_match) {
455 match_count_text_->set_background( 452 match_count_text_->set_background(
456 views::Background::CreateSolidBackground(kBackgroundColorNoMatch)); 453 views::Background::CreateSolidBackground(kBackgroundColorNoMatch));
457 match_count_text_->SetColor(kTextColorNoMatch); 454 match_count_text_->SetEnabledColor(kTextColorNoMatch);
458 } else { 455 } else {
459 match_count_text_->set_background( 456 match_count_text_->set_background(
460 views::Background::CreateSolidBackground(kBackgroundColorMatch)); 457 views::Background::CreateSolidBackground(kBackgroundColorMatch));
461 match_count_text_->SetColor(kTextColorMatchCount); 458 match_count_text_->SetEnabledColor(kTextColorMatchCount);
462 } 459 }
460 match_count_text_->SetBackgroundColor(
461 match_count_text_->background()->get_color());
463 } 462 }
464 463
465 bool FindBarView::FocusForwarderView::OnMousePressed( 464 bool FindBarView::FocusForwarderView::OnMousePressed(
466 const views::MouseEvent& event) { 465 const views::MouseEvent& event) {
467 if (view_to_focus_on_mousedown_) { 466 if (view_to_focus_on_mousedown_) {
468 view_to_focus_on_mousedown_->ClearSelection(); 467 view_to_focus_on_mousedown_->ClearSelection();
469 view_to_focus_on_mousedown_->RequestFocus(); 468 view_to_focus_on_mousedown_->RequestFocus();
470 } 469 }
471 return true; 470 return true;
472 } 471 }
(...skipping 17 matching lines...) Expand all
490 489
491 void FindBarView::OnThemeChanged() { 490 void FindBarView::OnThemeChanged() {
492 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 491 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
493 if (GetThemeProvider()) { 492 if (GetThemeProvider()) {
494 close_button_->SetBackground( 493 close_button_->SetBackground(
495 GetThemeProvider()->GetColor(ThemeService::COLOR_TAB_TEXT), 494 GetThemeProvider()->GetColor(ThemeService::COLOR_TAB_TEXT),
496 rb.GetBitmapNamed(IDR_CLOSE_BAR), 495 rb.GetBitmapNamed(IDR_CLOSE_BAR),
497 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); 496 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK));
498 } 497 }
499 } 498 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_install_dialog_view.cc ('k') | chrome/browser/ui/views/first_run_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698