| OLD | NEW |
| 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/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 find_previous_button_ = find_previous; | 146 find_previous_button_ = find_previous; |
| 147 find_next_button_ = find_next; | 147 find_next_button_ = find_next; |
| 148 close_button_ = close; | 148 close_button_ = close; |
| 149 } else { | 149 } else { |
| 150 find_previous_button_ = new views::ImageButton(this); | 150 find_previous_button_ = new views::ImageButton(this); |
| 151 find_next_button_ = new views::ImageButton(this); | 151 find_next_button_ = new views::ImageButton(this); |
| 152 close_button_ = new views::ImageButton(this); | 152 close_button_ = new views::ImageButton(this); |
| 153 } | 153 } |
| 154 | 154 |
| 155 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); | 155 find_previous_button_->set_id(VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON); |
| 156 find_previous_button_->SetFocusable(true); | 156 find_previous_button_->SetFocusable(true); |
| 157 find_previous_button_->set_request_focus_on_press(false); | 157 find_previous_button_->set_request_focus_on_press(false); |
| 158 find_previous_button_->SetTooltipText( | 158 find_previous_button_->SetTooltipText( |
| 159 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); | 159 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); |
| 160 find_previous_button_->SetAccessibleName( | 160 find_previous_button_->SetAccessibleName( |
| 161 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); | 161 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); |
| 162 AddChildView(find_previous_button_); | 162 AddChildView(find_previous_button_); |
| 163 | 163 |
| 164 find_next_button_->set_tag(FIND_NEXT_TAG); | 164 find_next_button_->set_id(VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON); |
| 165 find_next_button_->SetFocusable(true); | 165 find_next_button_->SetFocusable(true); |
| 166 find_next_button_->set_request_focus_on_press(false); | 166 find_next_button_->set_request_focus_on_press(false); |
| 167 find_next_button_->SetTooltipText( | 167 find_next_button_->SetTooltipText( |
| 168 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); | 168 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); |
| 169 find_next_button_->SetAccessibleName( | 169 find_next_button_->SetAccessibleName( |
| 170 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); | 170 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); |
| 171 AddChildView(find_next_button_); | 171 AddChildView(find_next_button_); |
| 172 | 172 |
| 173 close_button_->set_tag(CLOSE_TAG); | 173 close_button_->set_id(VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON); |
| 174 close_button_->SetFocusable(true); | 174 close_button_->SetFocusable(true); |
| 175 close_button_->set_request_focus_on_press(false); | 175 close_button_->set_request_focus_on_press(false); |
| 176 close_button_->SetTooltipText( | 176 close_button_->SetTooltipText( |
| 177 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); | 177 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); |
| 178 close_button_->SetAccessibleName( | 178 close_button_->SetAccessibleName( |
| 179 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 179 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 180 close_button_->SetAnimationDuration(0); | 180 close_button_->SetAnimationDuration(0); |
| 181 AddChildView(close_button_); | 181 AddChildView(close_button_); |
| 182 | 182 |
| 183 // Create a focus forwarder view which sends focus to find_text_. | 183 // Create a focus forwarder view which sends focus to find_text_. |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); | 415 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); |
| 416 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); | 416 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); |
| 417 return prefsize; | 417 return prefsize; |
| 418 } | 418 } |
| 419 | 419 |
| 420 //////////////////////////////////////////////////////////////////////////////// | 420 //////////////////////////////////////////////////////////////////////////////// |
| 421 // FindBarView, views::ButtonListener implementation: | 421 // FindBarView, views::ButtonListener implementation: |
| 422 | 422 |
| 423 void FindBarView::ButtonPressed( | 423 void FindBarView::ButtonPressed( |
| 424 views::Button* sender, const ui::Event& event) { | 424 views::Button* sender, const ui::Event& event) { |
| 425 switch (sender->tag()) { | 425 switch (sender->id()) { |
| 426 case FIND_PREVIOUS_TAG: | 426 case VIEW_ID_FIND_IN_PAGE_PREVIOUS_BUTTON: |
| 427 case FIND_NEXT_TAG: | 427 case VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON: |
| 428 if (!find_text_->text().empty()) { | 428 if (!find_text_->text().empty()) { |
| 429 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( | 429 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents( |
| 430 find_bar_host()->GetFindBarController()->web_contents()); | 430 find_bar_host()->GetFindBarController()->web_contents()); |
| 431 find_tab_helper->StartFinding(find_text_->text(), | 431 find_tab_helper->StartFinding( |
| 432 sender->tag() == FIND_NEXT_TAG, | 432 find_text_->text(), |
| 433 false); // Not case sensitive. | 433 sender->id() == VIEW_ID_FIND_IN_PAGE_NEXT_BUTTON, |
| 434 false); // Not case sensitive. |
| 434 } | 435 } |
| 435 // Move focus to the find textfield. | 436 |
| 436 find_text_->RequestFocus(); | 437 if (event.IsMouseEvent()) { |
| 438 // Move focus to the find textfield. |
| 439 find_text_->RequestFocus(); |
| 440 } |
| 437 break; | 441 break; |
| 438 case CLOSE_TAG: | 442 case VIEW_ID_FIND_IN_PAGE_CLOSE_BUTTON: |
| 439 find_bar_host()->GetFindBarController()->EndFindSession( | 443 find_bar_host()->GetFindBarController()->EndFindSession( |
| 440 FindBarController::kKeepSelectionOnPage, | 444 FindBarController::kKeepSelectionOnPage, |
| 441 FindBarController::kKeepResultsInFindBox); | 445 FindBarController::kKeepResultsInFindBox); |
| 442 break; | 446 break; |
| 443 default: | 447 default: |
| 444 NOTREACHED() << L"Unknown button"; | 448 NOTREACHED() << L"Unknown button"; |
| 445 break; | 449 break; |
| 446 } | 450 } |
| 447 } | 451 } |
| 448 | 452 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 // sent for a lot more things than just the user nulling out the search | 598 // sent for a lot more things than just the user nulling out the search |
| 595 // terms. See http://crbug.com/45372. | 599 // terms. See http://crbug.com/45372. |
| 596 Profile* profile = | 600 Profile* profile = |
| 597 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 601 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 598 FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile); | 602 FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile); |
| 599 find_bar_state->set_last_prepopulate_text(base::string16()); | 603 find_bar_state->set_last_prepopulate_text(base::string16()); |
| 600 } | 604 } |
| 601 } | 605 } |
| 602 | 606 |
| 603 void FindBarView::UpdateMatchCountAppearance(bool no_match) { | 607 void FindBarView::UpdateMatchCountAppearance(bool no_match) { |
| 604 bool enable_buttons = !match_count_text_->text().empty() && !no_match; | 608 // Enable the buttons if there is a match or if there is a match count text |
| 609 // set (from a prepopulated view). |
| 610 bool enable_buttons = !match_count_text_->text().empty() || !no_match; |
| 605 find_previous_button_->SetEnabled(enable_buttons); | 611 find_previous_button_->SetEnabled(enable_buttons); |
| 606 find_next_button_->SetEnabled(enable_buttons); | 612 find_next_button_->SetEnabled(enable_buttons); |
| 607 | 613 |
| 608 if (ui::MaterialDesignController::IsModeMaterial()) | 614 if (ui::MaterialDesignController::IsModeMaterial()) |
| 609 return; | 615 return; |
| 610 | 616 |
| 611 if (no_match) { | 617 if (no_match) { |
| 612 match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch); | 618 match_count_text_->SetBackgroundColor(kBackgroundColorNoMatch); |
| 613 match_count_text_->SetEnabledColor(kTextColorNoMatch); | 619 match_count_text_->SetEnabledColor(kTextColorNoMatch); |
| 614 } else { | 620 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 SkColor text_color = | 663 SkColor text_color = |
| 658 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); | 664 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 659 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); | 665 match_count_text_->SetEnabledColor(SkColorSetA(text_color, 0x69)); |
| 660 separator_->SetColor(SkColorSetA(text_color, 0x26)); | 666 separator_->SetColor(SkColorSetA(text_color, 0x26)); |
| 661 } | 667 } |
| 662 | 668 |
| 663 SkColor FindBarView::GetTextColorForIcon() { | 669 SkColor FindBarView::GetTextColorForIcon() { |
| 664 return GetNativeTheme()->GetSystemColor( | 670 return GetNativeTheme()->GetSystemColor( |
| 665 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 671 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 666 } | 672 } |
| OLD | NEW |