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

Unified Diff: ui/views/examples/examples_window.cc

Issue 8687013: Get the examples to run in aura_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/examples/examples_window.h ('k') | ui/views/examples/link_example.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/examples/examples_window.cc
===================================================================
--- ui/views/examples/examples_window.cc (revision 111708)
+++ ui/views/examples/examples_window.cc (working copy)
@@ -19,7 +19,6 @@
#include "ui/views/examples/combobox_example.h"
#include "ui/views/examples/double_split_view_example.h"
#include "ui/views/examples/link_example.h"
-#include "ui/views/examples/menu_example.h"
#include "ui/views/examples/message_box_example.h"
#include "ui/views/examples/native_theme_button_example.h"
#include "ui/views/examples/native_theme_checkbox_example.h"
@@ -28,7 +27,6 @@
#include "ui/views/examples/scroll_view_example.h"
#include "ui/views/examples/single_split_view_example.h"
#include "ui/views/examples/tabbed_pane_example.h"
-#include "ui/views/examples/table2_example.h"
#include "ui/views/examples/text_example.h"
#include "ui/views/examples/textfield_example.h"
#include "ui/views/examples/throbber_example.h"
@@ -39,156 +37,133 @@
#include "ui/views/widget/widget.h"
#include "views/controls/label.h"
+#if !defined(USE_AURA)
+#include "ui/views/examples/menu_example.h"
+#include "ui/views/examples/table2_example.h"
#if defined(OS_WIN)
-// TableView is not yet ported to Linux.
#include "ui/views/examples/table_example.h"
#endif
+#endif
+
+namespace views {
namespace examples {
-ExamplesMain::ExamplesMain()
- : tabbed_pane_(NULL),
- contents_(NULL),
- status_label_(NULL) {
-}
+class ExampleBase;
-ExamplesMain::~ExamplesMain() {
- STLDeleteElements(&examples_);
-}
+class ExamplesWindowContents : public views::WidgetDelegateView {
+ public:
+ explicit ExamplesWindowContents(bool quit_on_close)
+ : tabbed_pane_(new views::TabbedPane),
+ status_label_(new views::Label),
+ quit_on_close_(quit_on_close) {
+ instance_ = this;
+ }
+ virtual ~ExamplesWindowContents() {
+ }
-void ExamplesMain::Init() {
- // Creates a window with the tabbed pane for each example,
- // and a label to print messages from each example.
- DCHECK(contents_ == NULL) << "Run called more than once.";
- contents_ = new views::View();
- contents_->set_background(views::Background::CreateStandardPanelBackground());
- views::GridLayout* layout = new views::GridLayout(contents_);
- contents_->SetLayoutManager(layout);
+ // Prints a message in the status area, at the bottom of the window.
+ void SetStatus(const std::string& status) {
+ status_label_->SetText(UTF8ToUTF16(status));
+ }
- views::ColumnSet* column_set = layout->AddColumnSet(0);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
- views::GridLayout::USE_PREF, 0, 0);
+ static ExamplesWindowContents* instance() { return instance_; }
- tabbed_pane_ = new views::TabbedPane();
- status_label_ = new views::Label();
+ private:
+ // Overridden from WidgetDelegateView:
+ virtual bool CanResize() const OVERRIDE { return true; }
+ virtual bool CanMaximize() const OVERRIDE { return true; }
+ virtual string16 GetWindowTitle() const OVERRIDE {
+ return ASCIIToUTF16("Views Examples");
+ }
+ virtual views::View* GetContentsView() OVERRIDE { return this; }
+ virtual void WindowClosing() OVERRIDE {
+ instance_ = NULL;
+ if (quit_on_close_)
+ MessageLoopForUI::current()->Quit();
+ }
- layout->StartRow(1, 0);
- layout->AddView(tabbed_pane_);
- layout->StartRow(0 /* no expand */, 0);
- layout->AddView(status_label_);
+ // Overridden from View:
+ virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child) {
+ if (is_add && child == this)
+ InitExamplesWindow();
+ }
- // TODO(satorux): The window is getting wide. Eventually, we would have
- // the second tabbed pane.
- views::Widget* window =
- views::Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 850, 300));
+ // Creates the layout within the examples window.
+ void InitExamplesWindow() {
+ set_background(views::Background::CreateStandardPanelBackground());
+ views::GridLayout* layout = new views::GridLayout(this);
+ SetLayoutManager(layout);
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1, 0);
+ layout->AddView(tabbed_pane_);
+ layout->StartRow(0 /* no expand */, 0);
+ layout->AddView(status_label_);
- // Keep these in alphabetical order!
- examples_.push_back(new BubbleExample(this));
- examples_.push_back(new ButtonExample(this));
- examples_.push_back(new ComboboxExample(this));
- examples_.push_back(new DoubleSplitViewExample(this));
- examples_.push_back(new LinkExample(this));
- examples_.push_back(new MenuExample(this));
- examples_.push_back(new MessageBoxExample(this));
- examples_.push_back(new NativeThemeButtonExample(this));
- examples_.push_back(new NativeThemeCheckboxExample(this));
- examples_.push_back(new ProgressBarExample(this));
- examples_.push_back(new RadioButtonExample(this));
- examples_.push_back(new ScrollViewExample(this));
- examples_.push_back(new SingleSplitViewExample(this));
- examples_.push_back(new TabbedPaneExample(this));
+ AddExamples();
+ }
+
+ // Adds all the individual examples to the tab strip.
+ void AddExamples() {
+ AddExample(new BubbleExample);
+ AddExample(new ButtonExample);
+ AddExample(new ComboboxExample);
+ AddExample(new DoubleSplitViewExample);
+ AddExample(new LinkExample);
+#if !defined(USE_AURA)
+ AddExample(new MenuExample);
+#endif
+ AddExample(new MessageBoxExample);
+ AddExample(new NativeThemeButtonExample);
+ AddExample(new NativeThemeCheckboxExample);
+ AddExample(new ProgressBarExample);
+ AddExample(new RadioButtonExample);
+ AddExample(new ScrollViewExample);
+ AddExample(new SingleSplitViewExample);
+ AddExample(new TabbedPaneExample);
+#if !defined(USE_AURA)
#if defined(OS_WIN)
- examples_.push_back(new TableExample(this));
+ AddExample(new TableExample);
#endif
- examples_.push_back(new Table2Example(this));
- examples_.push_back(new TextExample(this));
- examples_.push_back(new TextfieldExample(this));
- examples_.push_back(new ThrobberExample(this));
- examples_.push_back(new WidgetExample(this));
+ AddExample(new Table2Example);
+#endif
+ AddExample(new TextExample);
+ AddExample(new TextfieldExample);
+ AddExample(new ThrobberExample);
+ AddExample(new WidgetExample);
+ }
- for (std::vector<ExampleBase*>::const_iterator i(examples_.begin());
- i != examples_.end(); ++i)
- AddExample(*i);
+ // Adds a new example to the tabbed window.
+ void AddExample(ExampleBase* example) {
+ tabbed_pane_->AddTab(UTF8ToUTF16(example->example_title()),
+ example->example_view());
+ }
- window->Show();
-}
+ static ExamplesWindowContents* instance_;
+ views::TabbedPane* tabbed_pane_;
+ views::Label* status_label_;
+ bool quit_on_close_;
-void ExamplesMain::SetStatus(const std::string& status) {
- status_label_->SetText(UTF8ToUTF16(status));
-}
+ DISALLOW_COPY_AND_ASSIGN(ExamplesWindowContents);
+};
-void ExamplesMain::AddExample(ExampleBase* example) {
- tabbed_pane_->AddTab(UTF8ToUTF16(example->example_title()),
- example->example_view());
-}
+// static
+ExamplesWindowContents* ExamplesWindowContents::instance_ = NULL;
-bool ExamplesMain::CanResize() const {
- return true;
+void ShowExamplesWindow(bool quit_on_close) {
+ if (ExamplesWindowContents::instance()) {
+ ExamplesWindowContents::instance()->GetWidget()->Activate();
+ } else {
+ Widget::CreateWindowWithBounds(new ExamplesWindowContents(quit_on_close),
+ gfx::Rect(0, 0, 850, 300))->Show();
+ }
}
-bool ExamplesMain::CanMaximize() const {
- return true;
+void LogStatus(const std::string& string) {
+ ExamplesWindowContents::instance()->SetStatus(string);
}
-string16 ExamplesMain::GetWindowTitle() const {
- return ASCIIToUTF16("Views Examples");
-}
-
-views::View* ExamplesMain::GetContentsView() {
- return contents_;
-}
-
-void ExamplesMain::WindowClosing() {
- MessageLoopForUI::current()->Quit();
-}
-
-views::Widget* ExamplesMain::GetWidget() {
- return contents_->GetWidget();
-}
-
-const views::Widget* ExamplesMain::GetWidget() const {
- return contents_->GetWidget();
-}
-
} // namespace examples
-
-int main(int argc, char** argv) {
-#if defined(OS_WIN)
- OleInitialize(NULL);
-#elif defined(OS_LINUX)
- // Initializes gtk stuff.
- g_type_init();
- gtk_init(&argc, &argv);
-#endif
- CommandLine::Init(argc, argv);
-
- base::EnableTerminationOnHeapCorruption();
-
- // The exit manager is in charge of calling the dtors of singleton objects.
- base::AtExitManager exit_manager;
-
- ui::RegisterPathProvider();
- bool icu_result = icu_util::Initialize();
- CHECK(icu_result);
- ui::ResourceBundle::InitSharedInstance("en-US");
-
- MessageLoop main_message_loop(MessageLoop::TYPE_UI);
-
- views::TestViewsDelegate delegate;
-
- // We do not use this header: chrome/common/chrome_switches.h
- // because that would create a bad dependency back on Chrome.
- views::Widget::SetPureViews(
- CommandLine::ForCurrentProcess()->HasSwitch("use-pure-views"));
-
- examples::ExamplesMain main;
- main.Init();
-
- views::AcceleratorHandler accelerator_handler;
- MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler);
-
-#if defined(OS_WIN)
- OleUninitialize();
-#endif
- return 0;
-}
+} // namespace views
« no previous file with comments | « ui/views/examples/examples_window.h ('k') | ui/views/examples/link_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698