summaryrefslogtreecommitdiffstats
path: root/views/examples
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-09 00:35:27 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-09 00:35:27 +0000
commitfdc3c22cbbf495f5819eb9cbd867915bb9d33702 (patch)
treeab5b109ff2a4b34cbbed1d5ce24cde99bf104e30 /views/examples
parente82c747e5c09beeba226f4d319c687f10f3c123d (diff)
downloadchromium_src-fdc3c22cbbf495f5819eb9cbd867915bb9d33702.zip
chromium_src-fdc3c22cbbf495f5819eb9cbd867915bb9d33702.tar.gz
chromium_src-fdc3c22cbbf495f5819eb9cbd867915bb9d33702.tar.bz2
views: Add initial Throbber example.
BUG=None TEST=export GYP_DEFINES="toolkit_views", gclient runhooks, make -k view_examples, out/Debug/view_examples Go to the Trobber tab, see the throbber spinning. Review URL: http://codereview.chromium.org/3345010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58901 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/examples')
-rw-r--r--views/examples/examples_main.cc7
-rw-r--r--views/examples/throbber_example.cc64
-rw-r--r--views/examples/throbber_example.h32
3 files changed, 102 insertions, 1 deletions
diff --git a/views/examples/examples_main.cc b/views/examples/examples_main.cc
index c3a0eb9..7b4b055 100644
--- a/views/examples/examples_main.cc
+++ b/views/examples/examples_main.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -30,6 +30,7 @@
#endif
#include "views/examples/table2_example.h"
#include "views/examples/textfield_example.h"
+#include "views/examples/throbber_example.h"
#include "views/examples/widget_example.h"
#include "views/focus/accelerator_handler.h"
#include "views/grid_layout.h"
@@ -96,6 +97,10 @@ void ExamplesMain::Run() {
tabbed_pane->AddTab(button_example.GetExampleTitle(),
button_example.GetExampleView());
+ examples::ThrobberExample throbber_example(this);
+ tabbed_pane->AddTab(throbber_example.GetExampleTitle(),
+ throbber_example.GetExampleView());
+
examples::ComboboxExample combobox_example(this);
tabbed_pane->AddTab(combobox_example.GetExampleTitle(),
combobox_example.GetExampleView());
diff --git a/views/examples/throbber_example.cc b/views/examples/throbber_example.cc
new file mode 100644
index 0000000..d03a9d9
--- /dev/null
+++ b/views/examples/throbber_example.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "views/examples/throbber_example.h"
+
+#include "views/controls/throbber.h"
+#include "views/fill_layout.h"
+#include "views/view.h"
+
+namespace {
+
+// Time in ms per throbber frame.
+const int kThrobberFrameMs = 60;
+
+class ThrobberView : public views::View {
+ public:
+ ThrobberView() {
+ throbber_ = new views::Throbber(kThrobberFrameMs, false);
+ AddChildView(throbber_);
+ throbber_->SetVisible(true);
+ throbber_->Start();
+ }
+
+ virtual gfx::Size GetPreferredSize() {
+ return gfx::Size(width(), height());
+ }
+
+ virtual void Layout() {
+ views::View* child = GetChildViewAt(0);
+ gfx::Size ps = child->GetPreferredSize();
+ child->SetBounds((width() - ps.width()) / 2,
+ (height() - ps.height()) / 2,
+ ps.width(), ps.height());
+ SizeToPreferredSize();
+ }
+
+ private:
+ views::Throbber* throbber_;
+
+ DISALLOW_COPY_AND_ASSIGN(ThrobberView);
+};
+
+} // namespace
+
+namespace examples {
+
+ThrobberExample::ThrobberExample(ExamplesMain* main)
+ : ExampleBase(main) {
+}
+
+ThrobberExample::~ThrobberExample() {
+}
+
+std::wstring ThrobberExample::GetExampleTitle() {
+ return L"Throbber";
+}
+
+void ThrobberExample::CreateExampleView(views::View* container) {
+ container->SetLayoutManager(new views::FillLayout());
+ container->AddChildView(new ThrobberView());
+}
+
+} // namespace examples
diff --git a/views/examples/throbber_example.h b/views/examples/throbber_example.h
new file mode 100644
index 0000000..9cbc160b
--- /dev/null
+++ b/views/examples/throbber_example.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef VIEWS_EXAMPLES_THROBBER_EXAMPLE_H_
+#define VIEWS_EXAMPLES_THROBBER_EXAMPLE_H_
+#pragma once
+
+#include "views/examples/example_base.h"
+
+namespace views {
+class View;
+} // namespace views
+
+namespace examples {
+
+class ThrobberExample : public ExampleBase {
+ public:
+ explicit ThrobberExample(ExamplesMain* main);
+ virtual ~ThrobberExample();
+
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle();
+ virtual void CreateExampleView(views::View* container);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ThrobberExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_THROBBER_EXAMPLE_H_