Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / views / examples / example_base.cc
bloba06fc1dcfea3034bbcb7803fd106bd733e32b979
1 // Copyright (c) 2012 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.
5 #include "ui/views/examples/example_base.h"
7 #include <stdarg.h>
9 #include "base/strings/stringprintf.h"
10 #include "ui/views/view.h"
12 namespace views {
13 namespace examples {
15 // Logs the specified string to the status area of the examples window.
16 // This function can only be called if there is a visible examples window.
17 void LogStatus(const std::string& status);
19 namespace {
21 // TODO(oshima): Check if this special container is still necessary.
22 class ContainerView : public View {
23 public:
24 explicit ContainerView(ExampleBase* base)
25 : example_view_created_(false),
26 example_base_(base) {
29 private:
30 // View:
31 virtual void ViewHierarchyChanged(
32 const ViewHierarchyChangedDetails& details) OVERRIDE {
33 View::ViewHierarchyChanged(details);
34 // We're not using child == this because a Widget may not be
35 // available when this is added to the hierarchy.
36 if (details.is_add && GetWidget() && !example_view_created_) {
37 example_view_created_ = true;
38 example_base_->CreateExampleView(this);
42 // True if the example view has already been created, or false otherwise.
43 bool example_view_created_;
45 ExampleBase* example_base_;
47 DISALLOW_COPY_AND_ASSIGN(ContainerView);
50 } // namespace
52 ExampleBase::~ExampleBase() {}
54 ExampleBase::ExampleBase(const char* title) : example_title_(title) {
55 container_ = new ContainerView(this);
58 // Prints a message in the status area, at the bottom of the window.
59 void ExampleBase::PrintStatus(const char* format, ...) {
60 va_list ap;
61 va_start(ap, format);
62 std::string msg;
63 base::StringAppendV(&msg, format, ap);
64 LogStatus(msg);
67 } // namespace examples
68 } // namespace views