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

Unified Diff: ui/oak/oak_window.cc

Issue 9662022: Basic skeleton of a window/layer/view inspector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months 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
Index: ui/oak/oak_window.cc
===================================================================
--- ui/oak/oak_window.cc (revision 0)
+++ ui/oak/oak_window.cc (revision 0)
@@ -0,0 +1,156 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/oak/oak_window.h"
+
+#include "base/utf_string_conversions.h"
+#include "grit/ui_resources.h"
+#include "ui/aura/root_window.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/image/image.h"
+#include "ui/views/controls/tree/tree_view.h"
+#include "ui/views/layout/layout_constants.h"
+#include "ui/views/widget/widget.h"
+
+namespace oak {
+namespace internal {
+namespace {
+
+const SkColor kBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC);
+
+class DetailsView : public views::View {
+ public:
+ DetailsView() {}
+ virtual ~DetailsView() {}
+
+ // Overridden from views::View:
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ canvas->GetSkCanvas()->drawColor(SK_ColorYELLOW);
tfarina 2012/03/10 14:42:46 nit: canvas->sk_canvas()->drawColor(..);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DetailsView);
+};
+
+} // namespace
+
+// static
+views::Widget* OakWindow::instance_ = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+// OakWindow, public:
+
+OakWindow::OakWindow() : tree_(NULL), tree_container_(NULL), details_(NULL) {
+}
+
+OakWindow::~OakWindow() {
+ // The tree needs to be destroyed before the model.
+ tree_.reset();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// OakWindow, views::WidgetDelegateView implementation:
+
+bool OakWindow::CanResize() const {
+ return true;
+}
+
+bool OakWindow::CanMaximize() const {
+ return true;
+}
+
+string16 OakWindow::GetWindowTitle() const {
+ return ASCIIToUTF16("Oak");
+}
+
+views::View* OakWindow::GetContentsView() {
+ return this;
+}
+
+SkBitmap OakWindow::GetWindowIcon() {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ return *rb.GetImageNamed(IDR_OAK).ToSkBitmap();
+}
+
+bool OakWindow::ShouldShowWindowIcon() const {
+ return true;
+}
+
+void OakWindow::DeleteDelegate() {
+ instance_ = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// OakWindow, views::View overrides:
+
+void OakWindow::OnPaint(gfx::Canvas* canvas) {
+ canvas->GetSkCanvas()->drawColor(SK_ColorWHITE);
tfarina 2012/03/10 14:42:46 nit: canvas->sk_canvas()->drawColor(...);
+ canvas->FillRect(separator_rect_, kBorderColor);
+}
+
+void OakWindow::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ if (is_add && child == this)
+ Init();
+}
+
+void OakWindow::Layout() {
+ gfx::Rect content_bounds = GetLocalBounds();
+ content_bounds.Inset(views::kPanelHorizMargin, views::kPanelVertMargin);
+
+ int tree_height =
+ (content_bounds.height() / 2) - views::kUnrelatedControlVerticalSpacing;
+ gfx::Rect tree_bounds = content_bounds;
+ tree_bounds.set_height(tree_height);
+ tree_container_->SetBoundsRect(tree_bounds);
+
+ separator_rect_ = content_bounds;
+ separator_rect_.set_y(
+ tree_bounds.bottom() + views::kRelatedControlVerticalSpacing);
+ separator_rect_.set_height(1);
+
+ gfx::Rect details_bounds = content_bounds;
+ details_bounds.set_y(
+ separator_rect_.bottom() + views::kRelatedControlVerticalSpacing);
+ details_bounds.set_height(content_bounds.bottom() - details_bounds.y());
+ details_->SetBoundsRect(details_bounds);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// OakWindow, views::TreeViewController implementation:
+
+void OakWindow::OnTreeViewSelectionChanged(views::TreeView* tree) {
+ NOTIMPLEMENTED();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// OakWindow, private:
+
+void OakWindow::Init() {
+ tree_model_.reset(
+ GenerateModel(GetWidget()->GetNativeView()->GetRootWindow()));
+ tree_.reset(new views::TreeView);
+ tree_->set_parent_owned(false);
+ tree_->SetController(this);
+ tree_->SetModel(tree_model_.get());
+ tree_container_ = tree_->CreateParentIfNecessary();
+ AddChildView(tree_container_);
+ details_ = new DetailsView;
+ AddChildView(details_);
+}
+
+} // namespace internal
+
+void ShowOakWindow() {
+ if (!internal::OakWindow::instance_) {
+ internal::OakWindow::instance_ =
+ views::Widget::CreateWindowWithBounds(new internal::OakWindow,
+ gfx::Rect(10, 10, 500, 500));
+ }
+ internal::OakWindow::instance_->Show();
+}
+
+} // namespace oak
Property changes on: ui\oak\oak_window.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« ui/oak/oak_window.h ('K') | « ui/oak/oak_window.h ('k') | ui/resources/oak.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698