diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 22:50:30 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 22:50:30 +0000 |
commit | 453e6c70fc8710f92e89648bb13beb3b04bd369d (patch) | |
tree | e8a24001adaa906daf2d0321542bcbaf762b1e8e /ui | |
parent | cb4f20ea9fdd9f50f8f68e1a611123a745d2c365 (diff) | |
download | chromium_src-453e6c70fc8710f92e89648bb13beb3b04bd369d.zip chromium_src-453e6c70fc8710f92e89648bb13beb3b04bd369d.tar.gz chromium_src-453e6c70fc8710f92e89648bb13beb3b04bd369d.tar.bz2 |
Adds window property display. A table view (acting as a list) with formatted content below the tree view. This will do for now.
http://crbug.com/97266
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9689039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126492 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/oak/oak.gyp | 5 | ||||
-rw-r--r-- | ui/oak/oak_aura_window_display.cc | 162 | ||||
-rw-r--r-- | ui/oak/oak_aura_window_display.h | 38 | ||||
-rw-r--r-- | ui/oak/oak_details_model.h | 34 | ||||
-rw-r--r-- | ui/oak/oak_pretty_print.cc | 37 | ||||
-rw-r--r-- | ui/oak/oak_pretty_print.h | 22 | ||||
-rw-r--r-- | ui/oak/oak_window.cc | 43 | ||||
-rw-r--r-- | ui/oak/oak_window.h | 9 | ||||
-rw-r--r-- | ui/views/controls/table/table_view_views.cc | 3 |
9 files changed, 330 insertions, 23 deletions
diff --git a/ui/oak/oak.gyp b/ui/oak/oak.gyp index 2051845..a3090ac 100644 --- a/ui/oak/oak.gyp +++ b/ui/oak/oak.gyp @@ -29,11 +29,16 @@ 'sources': [ # All .cc, .h under oak, except unittests 'oak.h', + 'oak_aura_window_display.cc', + 'oak_aura_window_display.h', 'oak_export.h', + 'oak_pretty_print.cc', + 'oak_pretty_print.h', 'oak_tree_model.cc', 'oak_tree_model.h', 'oak_window.cc', 'oak_window.h', + 'oak_details_model.h', ], }, ], diff --git a/ui/oak/oak_aura_window_display.cc b/ui/oak/oak_aura_window_display.cc index e69de29..153685a 100644 --- a/ui/oak/oak_aura_window_display.cc +++ b/ui/oak/oak_aura_window_display.cc @@ -0,0 +1,162 @@ +// 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_aura_window_display.h" + +#include "base/logging.h" +#include "base/string_util.h" +#include "base/utf_string_conversions.h" +#include "ui/aura/window.h" +#include "ui/base/models/table_model_observer.h" +#include "ui/oak/oak_pretty_print.h" + +namespace oak { +namespace internal { +namespace { +enum { +ROW_ID = 0, +ROW_DELEGATE, +ROW_TYPE, +ROW_NAME, +ROW_TITLE, +ROW_TRANSPARENT, +ROW_LAYER, +ROW_VISIBLE, +ROW_BOUNDS, +ROW_SCREENBOUNDS, +ROW_TRANSFORM, +ROW_PARENT, +ROW_ROOTWINDOW, +ROW_TRANSIENTCHILDREN, +ROW_TRANSIENTPARENT, +ROW_USERDATA, +ROW_STOPSEVENTPROPAGATION, +ROW_IGNOREEVENTS, +ROW_HITTESTBOUNDSINSET, +ROW_CANFOCUS, +ROW_COUNT +}; + +// aura::Window-specific pretty printing. +string16 PropertyWithWindowType(int type) { + std::string property = "Type: "; + switch (type) { + case aura::client::WINDOW_TYPE_UNKNOWN: + property.append("WINDOW_TYPE_UNKNOWN"); + break; + case aura::client::WINDOW_TYPE_NORMAL: + property.append("WINDOW_TYPE_NORMAL"); + break; + case aura::client::WINDOW_TYPE_POPUP: + property.append("WINDOW_TYPE_POPUP"); + break; + case aura::client::WINDOW_TYPE_CONTROL: + property.append("WINDOW_TYPE_CONTROL"); + break; + case aura::client::WINDOW_TYPE_PANEL: + property.append("WINDOW_TYPE_PANEL"); + break; + case aura::client::WINDOW_TYPE_MENU: + property.append("WINDOW_TYPE_MENU"); + break; + case aura::client::WINDOW_TYPE_TOOLTIP: + property.append("WINDOW_TYPE_TOOLTIP"); + break; + default: + NOTREACHED(); + break; + } + return ASCIIToUTF16(property); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// OakAuraWindowDisplay, public: + +OakAuraWindowDisplay::OakAuraWindowDisplay() : observer_(NULL), window_(NULL) { +} + +OakAuraWindowDisplay::~OakAuraWindowDisplay() { +} + +//////////////////////////////////////////////////////////////////////////////// +// OakAuraWindowDisplay, OakDetailsModel overrides: + +void OakAuraWindowDisplay::SetValue(aura::Window* window) { + window_ = window; + observer_->OnModelChanged(); +} + +//////////////////////////////////////////////////////////////////////////////// +// OakAuraWindowDisplay, ui::TableModel implementation: + +int OakAuraWindowDisplay::RowCount() { + return ROW_COUNT; +} + +string16 OakAuraWindowDisplay::GetText(int row, int column_id) { + if (!window_) + return EmptyString16(); + + string16 text; + switch (row) { + case ROW_ID: + return PropertyWithInteger("Id: ", window_->id()); + case ROW_DELEGATE: + return PropertyWithVoidStar("Delegate: ", window_->delegate()); + case ROW_TYPE: + return PropertyWithWindowType(window_->type()); + case ROW_NAME: + return ASCIIToUTF16("Name: " + window_->name()); + case ROW_TITLE: + return ASCIIToUTF16("Title: ") + window_->title(); + case ROW_TRANSPARENT: + return PropertyWithBool("Transparent: ", window_->transparent()); + case ROW_LAYER: + return PropertyWithVoidStar("Layer: ", window_->layer()); + case ROW_VISIBLE: + return PropertyWithBool("Visible: ", window_->IsVisible()); + case ROW_BOUNDS: + return PropertyWithBounds("Bounds: ", window_->bounds()); + case ROW_SCREENBOUNDS: + return PropertyWithBounds("Screen Bounds: ", window_->GetScreenBounds()); + case ROW_TRANSFORM: + return ASCIIToUTF16("Transform:"); + case ROW_PARENT: + return PropertyWithVoidStar("Parent: ", window_->parent()); + case ROW_ROOTWINDOW: + return PropertyWithVoidStar("Root Window: ", window_->GetRootWindow()); + case ROW_TRANSIENTCHILDREN: + return PropertyWithInteger("Transient Children: ", + window_->transient_children().size()); + case ROW_TRANSIENTPARENT: + return PropertyWithVoidStar("Transient Parent: ", + window_->transient_parent()); + case ROW_USERDATA: + return PropertyWithVoidStar("User Data: ", window_->user_data()); + case ROW_STOPSEVENTPROPAGATION: + return PropertyWithBool("Stops event propagation: ", + window_->StopsEventPropagation()); + case ROW_IGNOREEVENTS: + return PropertyWithBool("Can receive events: ", + window_->CanReceiveEvents()); + case ROW_HITTESTBOUNDSINSET: + return PropertyWithInteger("Hit-test bounds inset: ", + window_->hit_test_bounds_inset()); + case ROW_CANFOCUS: + return PropertyWithBool("Can Focus: ", window_->CanFocus()); + default: + NOTREACHED(); + break; + } + return EmptyString16(); +} + +void OakAuraWindowDisplay::SetObserver(ui::TableModelObserver* observer) { + observer_ = observer; +} + +} // namespace internal +} // namespace oak diff --git a/ui/oak/oak_aura_window_display.h b/ui/oak/oak_aura_window_display.h index e69de29..c9818a8 100644 --- a/ui/oak/oak_aura_window_display.h +++ b/ui/oak/oak_aura_window_display.h @@ -0,0 +1,38 @@ +// 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. + +#ifndef UI_OAK_OAK_AURA_WINDOW_DISPLAY_H_ +#define UI_OAK_OAK_AURA_WINDOW_DISPLAY_H_ +#pragma once + +#include "base/compiler_specific.h" +#include "ui/oak/oak_details_model.h" + +namespace oak { +namespace internal { + +class OakAuraWindowDisplay : public OakDetailsModel { + public: + OakAuraWindowDisplay(); + virtual ~OakAuraWindowDisplay(); + + private: + // Overridden from OakDetailsModel: + virtual void SetValue(aura::Window* window) OVERRIDE; + + // Overridden from ui::TableModel: + virtual int RowCount() OVERRIDE; + virtual string16 GetText(int row, int column_id) OVERRIDE; + virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE; + + ui::TableModelObserver* observer_; + aura::Window* window_; + + DISALLOW_COPY_AND_ASSIGN(OakAuraWindowDisplay); +}; + +} // namespace internal +} // namespace oak + +#endif // UI_OAK_OAK_AURA_WINDOW_DISPLAY_H_ diff --git a/ui/oak/oak_details_model.h b/ui/oak/oak_details_model.h new file mode 100644 index 0000000..6d8b37a --- /dev/null +++ b/ui/oak/oak_details_model.h @@ -0,0 +1,34 @@ +// 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. + +#ifndef UI_OAK_OAK_DETAILS_MODEL_H_ +#define UI_OAK_OAK_DETAILS_MODEL_H_ +#pragma once + +#include "ui/base/models/table_model.h" + +namespace aura { +class Window; +} + +namespace oak { +namespace internal { + +class OakDetailsModel : public ui::TableModel { + public: + virtual ~OakDetailsModel() {} + + virtual void SetValue(aura::Window* window) = 0; + + protected: + OakDetailsModel() {} + + private: + DISALLOW_COPY_AND_ASSIGN(OakDetailsModel); +}; + +} // namespace internal +} // namespace oak + +#endif // UI_OAK_OAK_DETAILS_MODEL_H_ diff --git a/ui/oak/oak_pretty_print.cc b/ui/oak/oak_pretty_print.cc new file mode 100644 index 0000000..c9c5b30 --- /dev/null +++ b/ui/oak/oak_pretty_print.cc @@ -0,0 +1,37 @@ +// 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_pretty_print.h" + +#include "base/string_util.h" +#include "base/utf_string_conversions.h" +#include "base/string_number_conversions.h" +#include "base/stringprintf.h" +#include "ui/gfx/rect.h" + +namespace oak { +namespace internal { + +string16 PropertyWithInteger(const std::string& prefix, int value) { + return ASCIIToUTF16(prefix) + base::IntToString16(value); +} + +string16 PropertyWithVoidStar(const std::string& prefix, void* ptr) { + unsigned int cast_ptr = + static_cast<unsigned int>(reinterpret_cast<intptr_t>(ptr)); + return ASCIIToUTF16( + prefix + "0x" + (ptr ? base::StringPrintf("%x", cast_ptr) : "0")); +} + +string16 PropertyWithBool(const std::string& prefix, bool value) { + return ASCIIToUTF16(prefix + (value ? "true" : "false")); +} + +string16 PropertyWithBounds(const std::string& prefix, + const gfx::Rect& bounds) { + return ASCIIToUTF16(prefix + bounds.ToString()); +} + +} // namespace internal +} // namespace oak diff --git a/ui/oak/oak_pretty_print.h b/ui/oak/oak_pretty_print.h new file mode 100644 index 0000000..b99cd23 --- /dev/null +++ b/ui/oak/oak_pretty_print.h @@ -0,0 +1,22 @@ +// 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 "base/string16.h" + +namespace gfx { +class Rect; +} + +namespace oak { +namespace internal { + +// Functions that return a string consisting of a prefix and the supplied value +// converted to a pretty string representation. +string16 PropertyWithInteger(const std::string& prefix, int value); +string16 PropertyWithVoidStar(const std::string& prefix, void* ptr); +string16 PropertyWithBool(const std::string& prefix, bool value); +string16 PropertyWithBounds(const std::string& prefix, const gfx::Rect& bounds); + +} // namespace internal +} // namespace oak diff --git a/ui/oak/oak_window.cc b/ui/oak/oak_window.cc index af4736d..4d4d963 100644 --- a/ui/oak/oak_window.cc +++ b/ui/oak/oak_window.cc @@ -10,6 +10,8 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/image.h" +#include "ui/oak/oak_aura_window_display.h" +#include "ui/views/controls/table/table_view.h" #include "ui/views/controls/tree/tree_view.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" @@ -17,23 +19,7 @@ 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->sk_canvas()->drawColor(SK_ColorYELLOW); - } - - private: - DISALLOW_COPY_AND_ASSIGN(DetailsView); -}; - } // namespace // static @@ -46,8 +32,9 @@ OakWindow::OakWindow() : tree_(NULL), tree_container_(NULL), details_(NULL) { } OakWindow::~OakWindow() { - // The tree needs to be destroyed before the model. + // The tree/table need to be destroyed before the model. tree_.reset(); + details_.reset(); } //////////////////////////////////////////////////////////////////////////////// @@ -116,14 +103,14 @@ void OakWindow::Layout() { details_bounds.set_y( separator_rect_.bottom() + views::kRelatedControlVerticalSpacing); details_bounds.set_height(content_bounds.bottom() - details_bounds.y()); - details_->SetBoundsRect(details_bounds); + details_container_->SetBoundsRect(details_bounds); } //////////////////////////////////////////////////////////////////////////////// // OakWindow, views::TreeViewController implementation: void OakWindow::OnTreeViewSelectionChanged(views::TreeView* tree) { - NOTIMPLEMENTED(); + details_model_->SetValue(tree_model_->AsNode(tree->GetSelectedNode())->value); } //////////////////////////////////////////////////////////////////////////////// @@ -138,8 +125,22 @@ void OakWindow::Init() { tree_->SetModel(tree_model_.get()); tree_container_ = tree_->CreateParentIfNecessary(); AddChildView(tree_container_); - details_ = new DetailsView; - AddChildView(details_); + + details_model_.reset(new OakAuraWindowDisplay); + std::vector<ui::TableColumn> columns; + columns.push_back(ui::TableColumn()); + details_.reset(new views::TableView(details_model_.get(), + columns, + views::TEXT_ONLY, + true, + false, + false)); + details_->set_parent_owned(false); + details_container_ = details_->CreateParentIfNecessary(); + details_->SetModel(details_model_.get()); + AddChildView(details_container_); + + OnTreeViewSelectionChanged(tree_.get()); } } // namespace internal diff --git a/ui/oak/oak_window.h b/ui/oak/oak_window.h index 2406a66..dfa2799 100644 --- a/ui/oak/oak_window.h +++ b/ui/oak/oak_window.h @@ -10,10 +10,15 @@ #include "ui/views/controls/tree/tree_view_controller.h" #include "ui/views/widget/widget_delegate.h" +namespace views { +class TableView; +} + namespace oak { namespace internal { class OakTreeModel; +class OakDetailsModel; class OakWindow : public views::WidgetDelegateView, public views::TreeViewController { @@ -51,7 +56,9 @@ class OakWindow : public views::WidgetDelegateView, gfx::Rect separator_rect_; - views::View* details_; + scoped_ptr<views::TableView> details_; + scoped_ptr<OakDetailsModel> details_model_; + views::View* details_container_; DISALLOW_COPY_AND_ASSIGN(OakWindow); }; diff --git a/ui/views/controls/table/table_view_views.cc b/ui/views/controls/table/table_view_views.cc index aa71ce2..161d21c 100644 --- a/ui/views/controls/table/table_view_views.cc +++ b/ui/views/controls/table/table_view_views.cc @@ -37,7 +37,7 @@ TableView::TableView(ui::TableModel* model, bool single_selection, bool resizable_columns, bool autosize_columns) - : model_(model), + : model_(NULL), table_type_(table_type), table_view_observer_(NULL), selected_row_(-1), @@ -48,6 +48,7 @@ TableView::TableView(ui::TableModel* model, DCHECK(table_type == TEXT_ONLY || table_type == ICON_AND_TEXT); set_focusable(true); set_background(Background::CreateSolidBackground(SK_ColorWHITE)); + SetModel(model); } TableView::~TableView() { |