OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ui/oak/oak_window.h" |
| 6 |
| 7 #include "base/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/views/controls/tree/tree_view.h" |
| 14 #include "ui/views/layout/layout_constants.h" |
| 15 #include "ui/views/widget/widget.h" |
| 16 |
| 17 namespace oak { |
| 18 namespace internal { |
| 19 namespace { |
| 20 |
| 21 const SkColor kBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); |
| 22 |
| 23 class DetailsView : public views::View { |
| 24 public: |
| 25 DetailsView() {} |
| 26 virtual ~DetailsView() {} |
| 27 |
| 28 // Overridden from views::View: |
| 29 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 30 canvas->GetSkCanvas()->drawColor(SK_ColorYELLOW); |
| 31 } |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(DetailsView); |
| 35 }; |
| 36 |
| 37 } // namespace |
| 38 |
| 39 // static |
| 40 views::Widget* OakWindow::instance_ = NULL; |
| 41 |
| 42 //////////////////////////////////////////////////////////////////////////////// |
| 43 // OakWindow, public: |
| 44 |
| 45 OakWindow::OakWindow() : tree_(NULL), tree_container_(NULL), details_(NULL) { |
| 46 } |
| 47 |
| 48 OakWindow::~OakWindow() { |
| 49 // The tree needs to be destroyed before the model. |
| 50 tree_.reset(); |
| 51 } |
| 52 |
| 53 //////////////////////////////////////////////////////////////////////////////// |
| 54 // OakWindow, views::WidgetDelegateView implementation: |
| 55 |
| 56 bool OakWindow::CanResize() const { |
| 57 return true; |
| 58 } |
| 59 |
| 60 bool OakWindow::CanMaximize() const { |
| 61 return true; |
| 62 } |
| 63 |
| 64 string16 OakWindow::GetWindowTitle() const { |
| 65 return ASCIIToUTF16("Oak"); |
| 66 } |
| 67 |
| 68 views::View* OakWindow::GetContentsView() { |
| 69 return this; |
| 70 } |
| 71 |
| 72 SkBitmap OakWindow::GetWindowIcon() { |
| 73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 74 return *rb.GetImageNamed(IDR_OAK).ToSkBitmap(); |
| 75 } |
| 76 |
| 77 bool OakWindow::ShouldShowWindowIcon() const { |
| 78 return true; |
| 79 } |
| 80 |
| 81 void OakWindow::DeleteDelegate() { |
| 82 instance_ = NULL; |
| 83 } |
| 84 |
| 85 //////////////////////////////////////////////////////////////////////////////// |
| 86 // OakWindow, views::View overrides: |
| 87 |
| 88 void OakWindow::OnPaint(gfx::Canvas* canvas) { |
| 89 canvas->GetSkCanvas()->drawColor(SK_ColorWHITE); |
| 90 canvas->FillRect(separator_rect_, kBorderColor); |
| 91 } |
| 92 |
| 93 void OakWindow::ViewHierarchyChanged(bool is_add, |
| 94 views::View* parent, |
| 95 views::View* child) { |
| 96 if (is_add && child == this) |
| 97 Init(); |
| 98 } |
| 99 |
| 100 void OakWindow::Layout() { |
| 101 gfx::Rect content_bounds = GetLocalBounds(); |
| 102 content_bounds.Inset(views::kPanelHorizMargin, views::kPanelVertMargin); |
| 103 |
| 104 int tree_height = |
| 105 (content_bounds.height() / 2) - views::kUnrelatedControlVerticalSpacing; |
| 106 gfx::Rect tree_bounds = content_bounds; |
| 107 tree_bounds.set_height(tree_height); |
| 108 tree_container_->SetBoundsRect(tree_bounds); |
| 109 |
| 110 separator_rect_ = content_bounds; |
| 111 separator_rect_.set_y( |
| 112 tree_bounds.bottom() + views::kRelatedControlVerticalSpacing); |
| 113 separator_rect_.set_height(1); |
| 114 |
| 115 gfx::Rect details_bounds = content_bounds; |
| 116 details_bounds.set_y( |
| 117 separator_rect_.bottom() + views::kRelatedControlVerticalSpacing); |
| 118 details_bounds.set_height(content_bounds.bottom() - details_bounds.y()); |
| 119 details_->SetBoundsRect(details_bounds); |
| 120 } |
| 121 |
| 122 //////////////////////////////////////////////////////////////////////////////// |
| 123 // OakWindow, views::TreeViewController implementation: |
| 124 |
| 125 void OakWindow::OnTreeViewSelectionChanged(views::TreeView* tree) { |
| 126 NOTIMPLEMENTED(); |
| 127 } |
| 128 |
| 129 //////////////////////////////////////////////////////////////////////////////// |
| 130 // OakWindow, private: |
| 131 |
| 132 void OakWindow::Init() { |
| 133 tree_model_.reset( |
| 134 GenerateModel(GetWidget()->GetNativeView()->GetRootWindow())); |
| 135 tree_.reset(new views::TreeView); |
| 136 tree_->set_parent_owned(false); |
| 137 tree_->SetController(this); |
| 138 tree_->SetModel(tree_model_.get()); |
| 139 tree_container_ = tree_->CreateParentIfNecessary(); |
| 140 AddChildView(tree_container_); |
| 141 details_ = new DetailsView; |
| 142 AddChildView(details_); |
| 143 } |
| 144 |
| 145 } // namespace internal |
| 146 |
| 147 void ShowOakWindow() { |
| 148 if (!internal::OakWindow::instance_) { |
| 149 internal::OakWindow::instance_ = |
| 150 views::Widget::CreateWindowWithBounds(new internal::OakWindow, |
| 151 gfx::Rect(10, 10, 500, 500)); |
| 152 } |
| 153 internal::OakWindow::instance_->Show(); |
| 154 } |
| 155 |
| 156 } // namespace oak |
OLD | NEW |