summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authoroshima <oshima@chromium.org>2014-12-19 12:51:09 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-19 20:52:36 +0000
commitf62e152bb7a13135a597d9766eb79551d3a24a73 (patch)
tree6663854cba8c1d07976654fd93dc2a4ee1b6f6ba /ui
parent16f38e8107f49d00d6bfe694e33ea61d394aaa7b (diff)
downloadchromium_src-f62e152bb7a13135a597d9766eb79551d3a24a73.zip
chromium_src-f62e152bb7a13135a597d9766eb79551d3a24a73.tar.gz
chromium_src-f62e152bb7a13135a597d9766eb79551d3a24a73.tar.bz2
Use template specialization to generate WindowProperty code.
They used to be a inlined function in the header, which led to code generation when method is used. This changes the code generation only in DECLARE_WINDOW_PROPERTY_TYPE(). BUG=None R=sadrul@chromium.org Review URL: https://codereview.chromium.org/801953002 Cr-Commit-Position: refs/heads/master@{#309252}
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/client/aura_constants.cc2
-rw-r--r--ui/aura/client/focus_client.cc1
-rw-r--r--ui/aura/window.h6
-rw-r--r--ui/aura/window_property.h88
-rw-r--r--ui/aura/window_unittest.cc45
-rw-r--r--ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc2
-rw-r--r--ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc2
-rw-r--r--ui/wm/core/transient_window_manager.cc2
-rw-r--r--ui/wm/core/window_animations.cc2
9 files changed, 86 insertions, 64 deletions
diff --git a/ui/aura/client/aura_constants.cc b/ui/aura/client/aura_constants.cc
index f903bff..b54ee7e0 100644
--- a/ui/aura/client/aura_constants.cc
+++ b/ui/aura/client/aura_constants.cc
@@ -12,6 +12,8 @@ DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::ModalType)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, gfx::Rect*)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::InputMethod*)
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, ui::WindowShowState)
+DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, int)
+DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, void*)
namespace aura {
namespace client {
diff --git a/ui/aura/client/focus_client.cc b/ui/aura/client/focus_client.cc
index 1f24a80..0f69c5e 100644
--- a/ui/aura/client/focus_client.cc
+++ b/ui/aura/client/focus_client.cc
@@ -7,7 +7,6 @@
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_property.h"
-DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, aura::Window*)
DECLARE_WINDOW_PROPERTY_TYPE(aura::client::FocusClient*)
namespace aura {
diff --git a/ui/aura/window.h b/ui/aura/window.h
index d1cff7b..79b8467 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -52,6 +52,10 @@ class WindowTreeHost;
template<typename T>
struct WindowProperty;
+namespace subtle {
+class PropertyHelper;
+}
+
namespace test {
class WindowTestApi;
}
@@ -332,7 +336,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
friend class test::WindowTestApi;
friend class LayoutManager;
friend class WindowTargeter;
-
+ friend class subtle::PropertyHelper;
// Called by the public {Set,Get,Clear}Property functions.
int64 SetPropertyInternal(const void* key,
const char* name,
diff --git a/ui/aura/window_property.h b/ui/aura/window_property.h
index 0b1574e..23769d3 100644
--- a/ui/aura/window_property.h
+++ b/ui/aura/window_property.h
@@ -9,8 +9,7 @@
#include "ui/aura/aura_export.h"
#include "ui/aura/window.h"
-// This header should be included by code that defines WindowProperties. It
-// should not be included by code that only gets and sets WindowProperties.
+// This header should be included by code that defines WindowProperties.
//
// To define a new WindowProperty:
//
@@ -78,56 +77,69 @@ struct WindowProperty {
Window::PropertyDeallocator deallocator;
};
-template<typename T>
-void Window::SetProperty(const WindowProperty<T>* property, T value) {
- int64 old = SetPropertyInternal(
- property,
- property->name,
- value == property->default_value ? NULL : property->deallocator,
- WindowPropertyCaster<T>::ToInt64(value),
- WindowPropertyCaster<T>::ToInt64(property->default_value));
- if (property->deallocator &&
- old != WindowPropertyCaster<T>::ToInt64(property->default_value)) {
- (*property->deallocator)(old);
- }
-}
+namespace subtle {
-template<typename T>
-T Window::GetProperty(const WindowProperty<T>* property) const {
- return WindowPropertyCaster<T>::FromInt64(GetPropertyInternal(
- property, WindowPropertyCaster<T>::ToInt64(property->default_value)));
-}
+class AURA_EXPORT PropertyHelper {
+ public:
+ template<typename T>
+ static void Set(Window* window, const WindowProperty<T>* property, T value) {
+ int64 old = window->SetPropertyInternal(
+ property,
+ property->name,
+ value == property->default_value ? nullptr : property->deallocator,
+ WindowPropertyCaster<T>::ToInt64(value),
+ WindowPropertyCaster<T>::ToInt64(property->default_value));
+ if (property->deallocator &&
+ old != WindowPropertyCaster<T>::ToInt64(property->default_value)) {
+ (*property->deallocator)(old);
+ }
+ }
+ template<typename T>
+ static T Get(const Window* window, const WindowProperty<T>* property) {
+ return WindowPropertyCaster<T>::FromInt64(window->GetPropertyInternal(
+ property, WindowPropertyCaster<T>::ToInt64(property->default_value)));
+ }
+ template<typename T>
+ static void Clear(Window* window, const WindowProperty<T>* property) {
+ window->SetProperty(property, property->default_value); \
+ }
+};
-template<typename T>
-void Window::ClearProperty(const WindowProperty<T>* property) {
- SetProperty(property, property->default_value);
-}
+} // namespace subtle
} // namespace aura
// Macros to instantiate the property getter/setter template functions.
#define DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(EXPORT, T) \
- template EXPORT void aura::Window::SetProperty( \
- const aura::WindowProperty<T >*, T); \
- template EXPORT T aura::Window::GetProperty( \
- const aura::WindowProperty<T >*) const; \
- template EXPORT void aura::Window::ClearProperty( \
- const aura::WindowProperty<T >*);
+ template<> EXPORT void aura::Window::SetProperty( \
+ const aura::WindowProperty<T >* property, T value) { \
+ subtle::PropertyHelper::Set<T>(this, property, value); \
+ } \
+ template<> EXPORT T aura::Window::GetProperty( \
+ const aura::WindowProperty<T >* property) const { \
+ return subtle::PropertyHelper::Get<T>(this, property); \
+ } \
+ template<> EXPORT void aura::Window::ClearProperty( \
+ const aura::WindowProperty<T >* property) { \
+ subtle::PropertyHelper::Clear<T>(this, property); \
+ }
#define DECLARE_WINDOW_PROPERTY_TYPE(T) \
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(, T)
#define DEFINE_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \
- COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64), property_type_too_large); \
- namespace { \
- const aura::WindowProperty<TYPE> NAME ## _Value = {DEFAULT, #NAME, NULL}; \
- } \
+ COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64), property_type_too_large); \
+ namespace { \
+ const aura::WindowProperty<TYPE> NAME ## _Value = \
+ {DEFAULT, #NAME, nullptr}; \
+ } \
const aura::WindowProperty<TYPE>* const NAME = & NAME ## _Value;
#define DEFINE_LOCAL_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \
- COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64), property_type_too_large); \
- namespace { \
- const aura::WindowProperty<TYPE> NAME ## _Value = {DEFAULT, #NAME, NULL}; \
- const aura::WindowProperty<TYPE>* const NAME = & NAME ## _Value; \
+ COMPILE_ASSERT(sizeof(TYPE) <= sizeof(int64), property_type_too_large); \
+ namespace { \
+ const aura::WindowProperty<TYPE> NAME ## _Value = \
+ {DEFAULT, #NAME, nullptr}; \
+ const aura::WindowProperty<TYPE>* const NAME = & NAME ## _Value; \
}
#define DEFINE_OWNED_WINDOW_PROPERTY_KEY(TYPE, NAME, DEFAULT) \
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 7276113..31bbf13 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -45,7 +45,29 @@
#include "ui/gfx/vector2d.h"
DECLARE_WINDOW_PROPERTY_TYPE(const char*)
-DECLARE_WINDOW_PROPERTY_TYPE(int)
+
+namespace {
+
+class TestProperty {
+ public:
+ TestProperty() {}
+ ~TestProperty() {
+ last_deleted_ = this;
+ }
+ static TestProperty* last_deleted() { return last_deleted_; }
+
+ private:
+ static TestProperty* last_deleted_;
+ DISALLOW_COPY_AND_ASSIGN(TestProperty);
+};
+
+TestProperty* TestProperty::last_deleted_ = nullptr;
+
+DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL);
+
+} // namespace
+
+DECLARE_WINDOW_PROPERTY_TYPE(TestProperty*);
namespace aura {
namespace test {
@@ -1582,27 +1604,6 @@ TEST_F(WindowTest, Property) {
EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey));
}
-namespace {
-
-class TestProperty {
- public:
- TestProperty() {}
- virtual ~TestProperty() {
- last_deleted_ = this;
- }
- static TestProperty* last_deleted() { return last_deleted_; }
-
- private:
- static TestProperty* last_deleted_;
- DISALLOW_COPY_AND_ASSIGN(TestProperty);
-};
-
-TestProperty* TestProperty::last_deleted_ = NULL;
-
-DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL);
-
-} // namespace
-
TEST_F(WindowTest, OwnedProperty) {
scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window()));
EXPECT_EQ(NULL, w->GetProperty(kOwnedKey));
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
index 3752373..0f7c92f 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
@@ -40,6 +40,8 @@
#include "ui/wm/core/window_animations.h"
#include "ui/wm/public/scoped_tooltip_disabler.h"
+DECLARE_WINDOW_PROPERTY_TYPE(views::DesktopWindowTreeHostWin*);
+
namespace views {
namespace {
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index dd8aa40..5699a72 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -53,6 +53,8 @@
#include "ui/wm/core/compound_event_filter.h"
#include "ui/wm/core/window_util.h"
+DECLARE_WINDOW_PROPERTY_TYPE(views::DesktopWindowTreeHostX11*);
+
namespace views {
DesktopWindowTreeHostX11* DesktopWindowTreeHostX11::g_current_capture =
diff --git a/ui/wm/core/transient_window_manager.cc b/ui/wm/core/transient_window_manager.cc
index 923f4a2..2ca145d 100644
--- a/ui/wm/core/transient_window_manager.cc
+++ b/ui/wm/core/transient_window_manager.cc
@@ -17,6 +17,8 @@
using aura::Window;
+DECLARE_WINDOW_PROPERTY_TYPE(wm::TransientWindowManager*);
+
namespace wm {
namespace {
diff --git a/ui/wm/core/window_animations.cc b/ui/wm/core/window_animations.cc
index 03bb1b9..fb671bb 100644
--- a/ui/wm/core/window_animations.cc
+++ b/ui/wm/core/window_animations.cc
@@ -38,11 +38,9 @@
#include "ui/wm/core/wm_core_switches.h"
#include "ui/wm/public/animation_host.h"
-DECLARE_WINDOW_PROPERTY_TYPE(int)
DECLARE_WINDOW_PROPERTY_TYPE(wm::WindowVisibilityAnimationType)
DECLARE_WINDOW_PROPERTY_TYPE(wm::WindowVisibilityAnimationTransition)
DECLARE_WINDOW_PROPERTY_TYPE(float)
-DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(WM_EXPORT, bool)
namespace wm {
namespace {