diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-27 00:07:53 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-27 00:07:53 +0000 |
commit | 1e55cc910f25c8af743d5941ccdffd836bdf1de6 (patch) | |
tree | c1b5ad6e7026abcf88998619ed48d93c5a7a1cfa /ui/aura | |
parent | d5c14067f0153540b6f6f0f7a807b5f77b6877d6 (diff) | |
download | chromium_src-1e55cc910f25c8af743d5941ccdffd836bdf1de6.zip chromium_src-1e55cc910f25c8af743d5941ccdffd836bdf1de6.tar.gz chromium_src-1e55cc910f25c8af743d5941ccdffd836bdf1de6.tar.bz2 |
Move view property implmentation from NativeWidgetAura to window.
BUG=none
TEST=tbw
Review URL: http://codereview.chromium.org/8395039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107477 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/window.cc | 16 | ||||
-rw-r--r-- | ui/aura/window.h | 18 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 31 |
3 files changed, 65 insertions, 0 deletions
diff --git a/ui/aura/window.cc b/ui/aura/window.cc index 409454c..4a0fb35 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -17,6 +17,7 @@ #include "ui/aura/window_observer.h" #include "ui/aura/window_types.h" #include "ui/base/animation/multi_animation.h" +#include "ui/base/view_prop.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/layer.h" @@ -70,6 +71,8 @@ Window::~Window() { parent_->RemoveChild(this); FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); + + STLDeleteValues(&prop_map_); } void Window::Init(ui::Layer::LayerType layer_type) { @@ -421,6 +424,19 @@ bool Window::IsOrContainsFullscreenWindow() const { return false; } +void Window::SetProperty(const char* name, void* value) { + ui::ViewProp* prop = prop_map_[name]; + delete prop; + if (value) + prop_map_[name] = new ui::ViewProp(this, name, value); + else + prop_map_.erase(name); +} + +void* Window::GetProperty(const char* name) const { + return ui::ViewProp::GetValue(const_cast<gfx::NativeView>(this), name); +} + // static ui::Animation* Window::CreateDefaultAnimation() { std::vector<ui::MultiAnimation::Part> parts; diff --git a/ui/aura/window.h b/ui/aura/window.h index 8b236e2..a809f5d 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -6,6 +6,7 @@ #define UI_AURA_WINDOW_H_ #pragma once +#include <map> #include <vector> #include "base/basictypes.h" @@ -27,6 +28,7 @@ class Animation; class Compositor; class Layer; class Transform; +class ViewProp; } namespace aura { @@ -256,6 +258,15 @@ class AURA_EXPORT Window : public ui::LayerDelegate { // Returns true if this window is fullscreen or contains a fullscreen window. bool IsOrContainsFullscreenWindow() const; + // Sets the window property |value| for given |name|. Setting NULL + // removes the property. It uses |ui::ViewProp| to store the property. + // Please see the description of |prop_map_| for more details. + void SetProperty(const char* name, void* value); + + // Returns the window property for given |name|. Returns NULL if + // the property does not exist. + void* GetProperty(const char* name) const; + // Returns an animation configured with the default duration. All animations // should use this. Caller owns returned value. static ui::Animation* CreateDefaultAnimation(); @@ -338,6 +349,13 @@ class AURA_EXPORT Window : public ui::LayerDelegate { ObserverList<WindowObserver> observers_; + // We're using ViewProp to store the property (for now) instead of + // just using std::map because chrome is still using |ViewProp| class + // to create and access property. + // TODO(oshima): Consolidcate ViewProp and aura::window property + // implementation. + std::map<const char*, ui::ViewProp*> prop_map_; + DISALLOW_COPY_AND_ASSIGN(Window); }; diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index a6474c8..79a6e18 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -20,6 +20,7 @@ #include "ui/aura/window_delegate.h" #include "ui/aura/window_observer.h" #include "ui/base/keycodes/keyboard_codes.h" +#include "ui/base/view_prop.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/screen.h" @@ -1136,6 +1137,36 @@ TEST_F(ToplevelWindowTest, FullscreenAfterDesktopResize) { EXPECT_EQ(window_bounds, w1->bounds()); } +TEST_F(WindowTest, Property) { + scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL)); + const gfx::NativeView target = const_cast<const gfx::NativeView>(w.get()); + const char* key = "test"; + EXPECT_EQ(NULL, w->GetProperty(key)); + EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, key)); + + void* value = reinterpret_cast<void*>(static_cast<intptr_t>(1)); + w->SetProperty(key, value); + EXPECT_EQ(value, w->GetProperty(key)); + EXPECT_EQ(value, ui::ViewProp::GetValue(target, key)); + + // Overwrite the property with different value type. + w->SetProperty(key, static_cast<void*>(const_cast<char*>("string"))); + std::string expected("string"); + EXPECT_EQ(expected, + static_cast<const char*>(w->GetProperty(key))); + EXPECT_EQ(expected, + static_cast<const char*>(ui::ViewProp::GetValue(target, key))); + + // Non-existent property. + EXPECT_EQ(NULL, w->GetProperty("foo")); + EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, "foo")); + + // Set NULL and make sure the property is gone. + w->SetProperty(key, NULL); + EXPECT_EQ(NULL, w->GetProperty(key)); + EXPECT_EQ(NULL, ui::ViewProp::GetValue(target, key)); +} + class WindowObserverTest : public WindowTest, public WindowObserver { public: |