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

Side by Side Diff: mandoline/ui/desktop_ui/find_bar_view.cc

Issue 1371773003: mandoline: Add find in page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: General patch cleanup. Created 5 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
OLDNEW
(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 close_button_(new views::LabelButton(this, base::ASCIIToUTF16("Close"))) {
22 SetLayoutManager(layout_);
23
24 text_field_->set_controller(this);
25
26 AddChildView(text_field_);
27 AddChildView(match_count_label_);
28 AddChildView(close_button_);
29
30 layout_->SetDefaultFlex(1);
31 layout_->SetFlexForView(text_field_, 4);
32
33 SetVisible(false);
34 }
35
36 FindBarView::~FindBarView() {
37 }
38
39 void FindBarView::Show() {
40 SetVisible(true);
41 text_field_->RequestFocus();
42 }
43
44 void FindBarView::Hide() {
45 SetVisible(false);
46 }
47
48 void FindBarView::SetMatchLabel(int result, int total) {
49 std::string str = base::StringPrintf("%d of %d", result, total);
50 match_count_label_->SetVisible(true);
51 match_count_label_->SetText(base::UTF8ToUTF16(str));
52 }
53
54 void FindBarView::ContentsChanged(views::Textfield* sender,
55 const base::string16& new_contents) {
56 std::string contents = base::UTF16ToUTF8(new_contents);
57 delegate_->OnDoFind(contents);
58 }
59
60 void FindBarView::ButtonPressed(views::Button* sender,
61 const ui::Event& event) {
62 if (sender == close_button_)
63 delegate_->OnHideFindBar();
64 else
65 NOTREACHED();
66 }
67
68 } // namespace mandoline
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698