| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mandoline/ui/desktop_ui/find_bar_view.h" | |
| 6 | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "mandoline/ui/desktop_ui/find_bar_delegate.h" | |
| 10 #include "ui/views/controls/label.h" | |
| 11 #include "ui/views/controls/textfield/textfield.h" | |
| 12 #include "ui/views/layout/box_layout.h" | |
| 13 | |
| 14 namespace mandoline { | |
| 15 | |
| 16 FindBarView::FindBarView(FindBarDelegate* delegate) | |
| 17 : delegate_(delegate), | |
| 18 layout_(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)), | |
| 19 text_field_(new views::Textfield), | |
| 20 match_count_label_(new views::Label), | |
| 21 next_button_(new views::LabelButton(this, base::ASCIIToUTF16("Next"))), | |
| 22 prev_button_(new views::LabelButton(this, base::ASCIIToUTF16("Prev"))), | |
| 23 close_button_(new views::LabelButton(this, base::ASCIIToUTF16("Close"))) { | |
| 24 SetLayoutManager(layout_); | |
| 25 | |
| 26 text_field_->set_controller(this); | |
| 27 | |
| 28 AddChildView(text_field_); | |
| 29 AddChildView(match_count_label_); | |
| 30 AddChildView(next_button_); | |
| 31 AddChildView(prev_button_); | |
| 32 AddChildView(close_button_); | |
| 33 | |
| 34 layout_->SetDefaultFlex(0); | |
| 35 layout_->SetFlexForView(text_field_, 1); | |
| 36 | |
| 37 SetVisible(false); | |
| 38 SetMatchLabel(0, 0); | |
| 39 } | |
| 40 | |
| 41 FindBarView::~FindBarView() {} | |
| 42 | |
| 43 void FindBarView::Show() { | |
| 44 SetVisible(true); | |
| 45 text_field_->RequestFocus(); | |
| 46 } | |
| 47 | |
| 48 void FindBarView::Hide() { | |
| 49 last_find_string_.clear(); | |
| 50 SetVisible(false); | |
| 51 } | |
| 52 | |
| 53 void FindBarView::SetMatchLabel(int result, int total) { | |
| 54 std::string str = base::StringPrintf("%d of %d", result, total); | |
| 55 match_count_label_->SetVisible(true); | |
| 56 match_count_label_->SetText(base::UTF8ToUTF16(str)); | |
| 57 Layout(); | |
| 58 } | |
| 59 | |
| 60 void FindBarView::ContentsChanged(views::Textfield* sender, | |
| 61 const base::string16& new_contents) { | |
| 62 std::string contents = base::UTF16ToUTF8(new_contents); | |
| 63 last_find_string_ = contents; | |
| 64 delegate_->OnDoFind(contents, true); | |
| 65 } | |
| 66 | |
| 67 void FindBarView::ButtonPressed(views::Button* sender, const ui::Event& event) { | |
| 68 if (sender == next_button_) { | |
| 69 delegate_->OnDoFind(last_find_string_, true); | |
| 70 } else if (sender == prev_button_) { | |
| 71 delegate_->OnDoFind(last_find_string_, false); | |
| 72 } else if (sender == close_button_) { | |
| 73 last_find_string_.clear(); | |
| 74 delegate_->OnHideFindBar(); | |
| 75 } else { | |
| 76 NOTREACHED(); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 } // namespace mandoline | |
| OLD | NEW |