diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-03 22:14:11 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-03 22:14:11 +0000 |
commit | fecec563479589b3649b1283f8b7d0662704f12b (patch) | |
tree | 4c391b6b9dbb886644de5ad7f9aa2f5941508779 | |
parent | d8ab621fc2ed73e4e23ad534a3b896f269b66ac6 (diff) | |
download | chromium_src-fecec563479589b3649b1283f8b7d0662704f12b.zip chromium_src-fecec563479589b3649b1283f8b7d0662704f12b.tar.gz chromium_src-fecec563479589b3649b1283f8b7d0662704f12b.tar.bz2 |
Allow Source<T> and Details<T> to be instantiated with T = const Foo.
Review URL: http://codereview.chromium.org/118185
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17550 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_window_tracker.h | 19 | ||||
-rw-r--r-- | chrome/common/native_window_notification_source.h | 10 | ||||
-rw-r--r-- | chrome/common/notification_details.h | 9 | ||||
-rw-r--r-- | chrome/common/notification_source.h | 9 |
4 files changed, 19 insertions, 28 deletions
diff --git a/chrome/browser/automation/automation_window_tracker.h b/chrome/browser/automation/automation_window_tracker.h index a4e505a..53a48aa2 100644 --- a/chrome/browser/automation/automation_window_tracker.h +++ b/chrome/browser/automation/automation_window_tracker.h @@ -8,26 +8,7 @@ #include "base/gfx/native_widget_types.h" #include "build/build_config.h" #include "chrome/browser/automation/automation_resource_tracker.h" - -#if defined(OS_WIN) -// Since HWNDs aren't pointers, we can't have NativeWindow -// be directly a pointer and so must explicitly declare the Source types -// for it. #include "chrome/common/native_window_notification_source.h" -#elif defined(OS_LINUX) || defined(OS_MACOSX) -// But on Linux and Mac, it is a pointer so this definition suffices. -template<> -class Source<gfx::NativeWindow> : public NotificationSource { - public: - explicit Source(gfx::NativeWindow win) : NotificationSource(win) {} - - explicit Source(const NotificationSource& other) - : NotificationSource(other) {} - - gfx::NativeWindow operator->() const { return ptr(); } - gfx::NativeWindow ptr() const { return static_cast<gfx::NativeWindow>(ptr_); } -}; -#endif class AutomationWindowTracker : public AutomationResourceTracker<gfx::NativeWindow> { diff --git a/chrome/common/native_window_notification_source.h b/chrome/common/native_window_notification_source.h index 3db7e50..1cb270d 100644 --- a/chrome/common/native_window_notification_source.h +++ b/chrome/common/native_window_notification_source.h @@ -8,8 +8,10 @@ #include "base/gfx/native_widget_types.h" #include "chrome/common/notification_source.h" -// Specialization of the Source class for HWND. This is needed as the Source -// class expects a pointer type. +// Specialization of the Source class for native windows. On Windows, these are +// HWNDs rather than pointers, and since the Source class expects a pointer +// type, this is necessary. On Mac/Linux, these are pointers, so this is +// unnecessary but harmless. template<> class Source<gfx::NativeWindow> : public NotificationSource { public: @@ -19,7 +21,9 @@ class Source<gfx::NativeWindow> : public NotificationSource { : NotificationSource(other) {} gfx::NativeWindow operator->() const { return ptr(); } - gfx::NativeWindow ptr() const { return static_cast<gfx::NativeWindow>(ptr_); } + gfx::NativeWindow ptr() const { + return static_cast<gfx::NativeWindow>(const_cast<void*>(ptr_)); + } }; #endif // CHROME_COMMON_NATIVE_WINDOW_NOTIFICATION_SOURCE_H_ diff --git a/chrome/common/notification_details.h b/chrome/common/notification_details.h index c938542..ee10111 100644 --- a/chrome/common/notification_details.h +++ b/chrome/common/notification_details.h @@ -33,9 +33,11 @@ class NotificationDetails { } protected: - NotificationDetails(void* ptr) : ptr_(ptr) {} + NotificationDetails(const void* ptr) : ptr_(ptr) {} - void* ptr_; + // Declaring this const allows Details<T> to be used with both T = Foo and + // T = const Foo. + const void* ptr_; }; template <class T> @@ -46,7 +48,8 @@ class Details : public NotificationDetails { : NotificationDetails(other) {} T* operator->() const { return ptr(); } - T* ptr() const { return static_cast<T*>(ptr_); } + // The casts here allow this to compile with both T = Foo and T = const Foo. + T* ptr() const { return static_cast<T*>(const_cast<void*>(ptr_)); } }; #endif // CHROME_COMMON_NOTIFICATION_DETAILS_H__ diff --git a/chrome/common/notification_source.h b/chrome/common/notification_source.h index 93b20ba..fb37124 100644 --- a/chrome/common/notification_source.h +++ b/chrome/common/notification_source.h @@ -31,9 +31,11 @@ class NotificationSource { } protected: - NotificationSource(void* ptr) : ptr_(ptr) {} + NotificationSource(const void* ptr) : ptr_(ptr) {} - void* ptr_; + // Declaring this const allows Source<T> to be used with both T = Foo and + // T = const Foo. + const void* ptr_; }; template <class T> @@ -45,7 +47,8 @@ class Source : public NotificationSource { : NotificationSource(other) {} T* operator->() const { return ptr(); } - T* ptr() const { return static_cast<T*>(ptr_); } + // The casts here allow this to compile with both T = Foo and T = const Foo. + T* ptr() const { return static_cast<T*>(const_cast<void*>(ptr_)); } }; #endif // CHROME_COMMON_NOTIFICATION_SOURCE_H__ |