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"
9 #include "base/strings/stringprintf.h"
10 #include "ui/views/view.h"
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
);
21 // TODO(oshima): Check if this special container is still necessary.
22 class ContainerView
: public View
{
24 explicit ContainerView(ExampleBase
* base
)
25 : example_view_created_(false),
31 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
);
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
, ...) {
63 base::StringAppendV(&msg
, format
, ap
);
67 } // namespace examples