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/oak/oak_window.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "grit/ui_resources.h"
9 #include "ui/aura/root_window.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/image/image.h"
13 #include "ui/oak/oak.h"
14 #include "ui/oak/oak_aura_window_display.h"
15 #include "ui/views/controls/table/table_view.h"
16 #include "ui/views/controls/tree/tree_view.h"
17 #include "ui/views/layout/layout_constants.h"
18 #include "ui/views/widget/widget.h"
23 const SkColor kBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC);
27 views::Widget* OakWindow::instance = NULL;
29 ////////////////////////////////////////////////////////////////////////////////
32 OakWindow::OakWindow() : tree_container_(NULL) {}
34 OakWindow::~OakWindow() {
35 // The tree/table need to be destroyed before the model.
40 ////////////////////////////////////////////////////////////////////////////////
41 // OakWindow, views::WidgetDelegateView implementation:
43 bool OakWindow::CanResize() const {
47 bool OakWindow::CanMaximize() const {
51 base::string16 OakWindow::GetWindowTitle() const {
52 return ASCIIToUTF16("Oak");
55 views::View* OakWindow::GetContentsView() {
59 gfx::ImageSkia OakWindow::GetWindowIcon() {
60 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
61 return *rb.GetImageNamed(IDR_OAK).ToImageSkia();
64 bool OakWindow::ShouldShowWindowIcon() const {
68 void OakWindow::DeleteDelegate() {
73 ////////////////////////////////////////////////////////////////////////////////
74 // OakWindow, views::View overrides:
76 void OakWindow::OnPaint(gfx::Canvas* canvas) {
77 canvas->DrawColor(SK_ColorWHITE);
78 canvas->FillRect(separator_rect_, kBorderColor);
81 void OakWindow::ViewHierarchyChanged(
82 const ViewHierarchyChangedDetails& details) {
83 if (details.is_add && details.child == this)
87 void OakWindow::Layout() {
88 gfx::Rect content_bounds = GetLocalBounds();
89 content_bounds.Inset(views::kPanelHorizMargin, views::kPanelVertMargin);
92 (content_bounds.height() / 2) - views::kUnrelatedControlVerticalSpacing;
93 gfx::Rect tree_bounds = content_bounds;
94 tree_bounds.set_height(tree_height);
95 tree_container_->SetBoundsRect(tree_bounds);
97 separator_rect_ = content_bounds;
98 separator_rect_.set_y(
99 tree_bounds.bottom() + views::kRelatedControlVerticalSpacing);
100 separator_rect_.set_height(1);
102 gfx::Rect details_bounds = content_bounds;
103 details_bounds.set_y(
104 separator_rect_.bottom() + views::kRelatedControlVerticalSpacing);
105 details_bounds.set_height(content_bounds.bottom() - details_bounds.y());
106 details_container_->SetBoundsRect(details_bounds);
109 ////////////////////////////////////////////////////////////////////////////////
110 // OakWindow, views::TreeViewController implementation:
112 void OakWindow::OnTreeViewSelectionChanged(views::TreeView* tree) {
113 details_model_->SetValue(tree_model_->AsNode(tree->GetSelectedNode())->value);
116 ////////////////////////////////////////////////////////////////////////////////
117 // OakWindow, private:
119 void OakWindow::Init() {
121 GenerateModel(GetWidget()->GetNativeView()->GetRootWindow()));
122 tree_.reset(new views::TreeView);
123 tree_->set_owned_by_client();
124 tree_->SetController(this);
125 tree_->SetModel(tree_model_.get());
126 tree_container_ = tree_->CreateParentIfNecessary();
127 AddChildView(tree_container_);
129 details_model_.reset(new OakAuraWindowDisplay);
130 std::vector<ui::TableColumn> columns;
131 columns.push_back(ui::TableColumn());
132 details_.reset(new views::TableView(details_model_.get(),
136 details_->set_owned_by_client();
137 details_container_ = details_->CreateParentIfNecessary();
138 details_->SetModel(details_model_.get());
139 AddChildView(details_container_);
141 OnTreeViewSelectionChanged(tree_.get());
144 } // namespace internal
146 void ShowOakWindowWithContext(gfx::NativeView context) {
147 if (!internal::OakWindow::instance) {
148 // TODO(erg): Do we want to reuse this window in times with a different
149 // context? For now, this is OK, but if we ever use Oak outside of the ash
150 // shell, we run into crbug.com/165759.
151 internal::OakWindow::instance =
152 views::Widget::CreateWindowWithContextAndBounds(
153 new internal::OakWindow, context, gfx::Rect(10, 10, 500, 500));
155 internal::OakWindow::instance->Show();