From fdc3c22cbbf495f5819eb9cbd867915bb9d33702 Mon Sep 17 00:00:00 2001 From: "tfarina@chromium.org" Date: Thu, 9 Sep 2010 00:35:27 +0000 Subject: 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 --- views/examples/examples_main.cc | 7 ++++- views/examples/throbber_example.cc | 64 ++++++++++++++++++++++++++++++++++++++ views/examples/throbber_example.h | 32 +++++++++++++++++++ views/views.gyp | 2 ++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 views/examples/throbber_example.cc create mode 100644 views/examples/throbber_example.h (limited to 'views') 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_ diff --git a/views/views.gyp b/views/views.gyp index ef8ba07..8690022 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -474,6 +474,8 @@ 'examples/slider_example.h', 'examples/tabbed_pane_example.h', 'examples/textfield_example.h', + 'examples/throbber_example.cc', + 'examples/throbber_example.h', 'examples/widget_example.h', '<(SHARED_INTERMEDIATE_DIR)/app/app_resources/app_resources.rc', -- cgit v1.1