OLD | NEW |
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 "ui/views/examples/throbber_example.h" | 5 #include "ui/views/examples/throbber_example.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "ui/views/controls/throbber.h" | 8 #include "ui/views/controls/throbber.h" |
9 #include "ui/views/layout/fill_layout.h" | 9 #include "ui/views/layout/fill_layout.h" |
10 #include "ui/views/view.h" | 10 #include "ui/views/view.h" |
11 | 11 |
12 namespace views { | 12 namespace views { |
13 namespace examples { | 13 namespace examples { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class ThrobberView : public View { | 17 class ThrobberView : public View { |
18 public: | 18 public: |
19 ThrobberView() : throbber_(new Throbber()) { | 19 ThrobberView() : throbber_(new Throbber()), is_checked_(false) { |
20 AddChildView(throbber_); | 20 AddChildView(throbber_); |
21 throbber_->Start(); | 21 throbber_->Start(); |
22 } | 22 } |
23 | 23 |
| 24 // View:: |
24 gfx::Size GetPreferredSize() const override { | 25 gfx::Size GetPreferredSize() const override { |
25 return gfx::Size(width(), height()); | 26 return gfx::Size(width(), height()); |
26 } | 27 } |
27 | 28 |
28 void Layout() override { | 29 void Layout() override { |
29 int diameter = 64; | 30 int diameter = 16; |
30 throbber_->SetBounds((width() - diameter) / 2, | 31 throbber_->SetBounds((width() - diameter) / 2, |
31 (height() - diameter) / 2, | 32 (height() - diameter) / 2, |
32 diameter, diameter); | 33 diameter, diameter); |
33 SizeToPreferredSize(); | 34 SizeToPreferredSize(); |
34 } | 35 } |
35 | 36 |
| 37 bool OnMousePressed(const ui::MouseEvent& event) override { |
| 38 if (GetEventHandlerForPoint(event.location()) != throbber_) |
| 39 return false; |
| 40 |
| 41 if (is_checked_) |
| 42 throbber_->Start(); |
| 43 else |
| 44 throbber_->Stop(); |
| 45 throbber_->SetChecked(!is_checked_); |
| 46 is_checked_ = !is_checked_; |
| 47 return true; |
| 48 } |
| 49 |
36 private: | 50 private: |
37 Throbber* throbber_; | 51 Throbber* throbber_; |
| 52 bool is_checked_; |
38 | 53 |
39 DISALLOW_COPY_AND_ASSIGN(ThrobberView); | 54 DISALLOW_COPY_AND_ASSIGN(ThrobberView); |
40 }; | 55 }; |
41 | 56 |
42 } // namespace | 57 } // namespace |
43 | 58 |
44 ThrobberExample::ThrobberExample() : ExampleBase("Throbber") { | 59 ThrobberExample::ThrobberExample() : ExampleBase("Throbber") { |
45 } | 60 } |
46 | 61 |
47 ThrobberExample::~ThrobberExample() { | 62 ThrobberExample::~ThrobberExample() { |
48 } | 63 } |
49 | 64 |
50 void ThrobberExample::CreateExampleView(View* container) { | 65 void ThrobberExample::CreateExampleView(View* container) { |
51 container->SetLayoutManager(new FillLayout()); | 66 container->SetLayoutManager(new FillLayout()); |
52 container->AddChildView(new ThrobberView()); | 67 container->AddChildView(new ThrobberView()); |
53 } | 68 } |
54 | 69 |
55 } // namespace examples | 70 } // namespace examples |
56 } // namespace views | 71 } // namespace views |
OLD | NEW |