diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-19 18:39:38 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-19 18:39:38 +0000 |
commit | ee3724cc8eb917d0296562fd54d170273d3b8820 (patch) | |
tree | fa10206563156f59ce8548c471e223eaf9be8d99 /views | |
parent | 0f4758f7f597d5f4b608f75aba2cec316d1b62b8 (diff) | |
download | chromium_src-ee3724cc8eb917d0296562fd54d170273d3b8820.zip chromium_src-ee3724cc8eb917d0296562fd54d170273d3b8820.tar.gz chromium_src-ee3724cc8eb917d0296562fd54d170273d3b8820.tar.bz2 |
Converts usage of SetProp/GetProp to a map. Even after making sure we
clean up props we still leak in a handful of cases that are causing
test grief. By and large our usage of properties is for inside the
application, so that a map works fine.
BUG=61528 44991
Review URL: http://codereview.chromium.org/5075003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66784 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/accessibility/view_accessibility.cc | 11 | ||||
-rw-r--r-- | views/accessibility/view_accessibility.h | 2 | ||||
-rw-r--r-- | views/controls/native_control.cc | 15 | ||||
-rw-r--r-- | views/controls/native_control_win.cc | 13 | ||||
-rw-r--r-- | views/controls/native_control_win.h | 8 | ||||
-rw-r--r-- | views/focus/focus_util_win.cc | 18 | ||||
-rw-r--r-- | views/focus/focus_util_win.h | 10 | ||||
-rw-r--r-- | views/widget/child_window_message_processor.cc | 13 | ||||
-rw-r--r-- | views/widget/child_window_message_processor.h | 8 | ||||
-rw-r--r-- | views/widget/widget.h | 5 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 12 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 5 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 46 | ||||
-rw-r--r-- | views/widget/widget_win.h | 13 |
14 files changed, 86 insertions, 93 deletions
diff --git a/views/accessibility/view_accessibility.cc b/views/accessibility/view_accessibility.cc index c092895..5d51d814 100644 --- a/views/accessibility/view_accessibility.cc +++ b/views/accessibility/view_accessibility.cc @@ -4,11 +4,12 @@ #include "views/accessibility/view_accessibility.h" +#include "app/view_prop.h" #include "views/widget/widget.h" #include "views/widget/widget_win.h" -const wchar_t kViewsNativeHostPropForAccessibility[] = - L"Views_NativeViewHostHWNDForAccessibility"; +const char kViewsNativeHostPropForAccessibility[] = + "Views_NativeViewHostHWNDForAccessibility"; // static scoped_refptr<ViewAccessibility> ViewAccessibility::Create(views::View* view) { @@ -710,9 +711,9 @@ HRESULT ViewAccessibility::GetNativeIAccessibleInterface( if (!native_host || !accessible) return E_INVALIDARG; - HWND native_view_window = - static_cast<HWND>(GetProp(native_host->native_view(), - kViewsNativeHostPropForAccessibility)); + HWND native_view_window = static_cast<HWND>( + app::ViewProp::GetValue(native_host->native_view(), + kViewsNativeHostPropForAccessibility)); if (!IsWindow(native_view_window)) { native_view_window = native_host->native_view(); } diff --git a/views/accessibility/view_accessibility.h b/views/accessibility/view_accessibility.h index 9803cba..66df163c 100644 --- a/views/accessibility/view_accessibility.h +++ b/views/accessibility/view_accessibility.h @@ -160,6 +160,6 @@ class ATL_NO_VTABLE ViewAccessibility DISALLOW_COPY_AND_ASSIGN(ViewAccessibility); }; -extern const wchar_t kViewsNativeHostPropForAccessibility[]; +extern const char kViewsNativeHostPropForAccessibility[]; #endif // VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_H_ diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc index ef719c9..13881bb 100644 --- a/views/controls/native_control.cc +++ b/views/controls/native_control.cc @@ -13,7 +13,7 @@ #include "app/keyboard_code_conversion_win.h" #include "app/keyboard_codes.h" #include "app/l10n_util_win.h" -#include "app/win/scoped_prop.h" +#include "app/view_prop.h" #include "base/logging.h" #include "base/scoped_ptr.h" #include "base/win_util.h" @@ -24,10 +24,12 @@ #include "views/focus/focus_manager.h" #include "views/widget/widget.h" +using app::ViewProp; + namespace views { // Maps to the NativeControl. -static const wchar_t* const kNativeControlKey = L"__NATIVE_CONTROL__"; +static const char* const kNativeControlKey = "__NATIVE_CONTROL__"; class NativeControlContainer : public CWindowImpl<NativeControlContainer, CWindow, @@ -89,8 +91,7 @@ class NativeControlContainer : public CWindowImpl<NativeControlContainer, // We subclass the control hwnd so we get the WM_KEYDOWN messages. original_handler_ = win_util::SetWindowProc( control_, &NativeControl::NativeControlWndProc); - prop_.reset( - new app::win::ScopedProp(control_, kNativeControlKey , parent_)); + prop_.reset(new ViewProp(control_, kNativeControlKey , parent_)); ::ShowWindow(control_, SW_SHOW); return 1; @@ -166,7 +167,7 @@ class NativeControlContainer : public CWindowImpl<NativeControlContainer, // Message handler that was set before we reset it. WNDPROC original_handler_; - scoped_ptr<app::win::ScopedProp> prop_; + scoped_ptr<ViewProp> prop_; DISALLOW_COPY_AND_ASSIGN(NativeControlContainer); }; @@ -363,8 +364,8 @@ LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message, WPARAM w_param, LPARAM l_param) { - NativeControl* native_control = - static_cast<NativeControl*>(GetProp(window, kNativeControlKey)); + NativeControl* native_control = static_cast<NativeControl*>( + ViewProp::GetValue(window, kNativeControlKey)); DCHECK(native_control); WNDPROC original_handler = native_control->container_->original_handler_; DCHECK(original_handler); diff --git a/views/controls/native_control_win.cc b/views/controls/native_control_win.cc index c4f811c..a223993 100644 --- a/views/controls/native_control_win.cc +++ b/views/controls/native_control_win.cc @@ -7,14 +7,16 @@ #include <windowsx.h> #include "app/l10n_util_win.h" -#include "app/win/scoped_prop.h" +#include "app/view_prop.h" #include "base/logging.h" #include "base/win_util.h" #include "views/focus/focus_manager.h" +using app::ViewProp; + namespace views { -static const wchar_t* kNativeControlWinKey = L"__NATIVE_CONTROL_WIN__"; +static const char* const kNativeControlWinKey = "__NATIVE_CONTROL_WIN__"; //////////////////////////////////////////////////////////////////////////////// // NativeControlWin, public: @@ -130,8 +132,7 @@ void NativeControlWin::ShowContextMenu(const gfx::Point& location) { void NativeControlWin::NativeControlCreated(HWND native_control) { // Associate this object with the control's HWND so that WidgetWin can find // this object when it receives messages from it. - props_.push_back( - new app::win::ScopedProp(native_control, kNativeControlWinKey, this)); + props_.push_back(new ViewProp(native_control, kNativeControlWinKey, this)); props_.push_back(ChildWindowMessageProcessor::Register(native_control, this)); // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages. @@ -196,8 +197,8 @@ LRESULT NativeControlWin::NativeControlWndProc(HWND window, UINT message, WPARAM w_param, LPARAM l_param) { - NativeControlWin* native_control = - static_cast<NativeControlWin*>(GetProp(window, kNativeControlWinKey)); + NativeControlWin* native_control = reinterpret_cast<NativeControlWin*>( + ViewProp::GetValue(window, kNativeControlWinKey)); DCHECK(native_control); if (message == WM_KEYDOWN && diff --git a/views/controls/native_control_win.h b/views/controls/native_control_win.h index 3733a15..d27efa4 100644 --- a/views/controls/native_control_win.h +++ b/views/controls/native_control_win.h @@ -13,9 +13,7 @@ #include "views/widget/child_window_message_processor.h" namespace app { -namespace win { -class ScopedProp; -} +class ViewProp; } namespace views { @@ -75,7 +73,7 @@ class NativeControlWin : public ChildWindowMessageProcessor, DWORD GetAdditionalRTLStyle() const; private: - typedef ScopedVector<app::win::ScopedProp> ScopedProps; + typedef ScopedVector<app::ViewProp> ViewProps; // Called by the containing WidgetWin when a message of type WM_CTLCOLORBTN or // WM_CTLCOLORSTATIC is sent from the HWND created by an object dreived from @@ -91,7 +89,7 @@ class NativeControlWin : public ChildWindowMessageProcessor, // The window procedure before we subclassed. WNDPROC original_wndproc_; - ScopedProps props_; + ViewProps props_; DISALLOW_COPY_AND_ASSIGN(NativeControlWin); }; diff --git a/views/focus/focus_util_win.cc b/views/focus/focus_util_win.cc index 266a891..23172ad 100644 --- a/views/focus/focus_util_win.cc +++ b/views/focus/focus_util_win.cc @@ -6,24 +6,26 @@ #include <windowsx.h> -#include "app/win/scoped_prop.h" +#include "app/view_prop.h" #include "base/auto_reset.h" #include "base/win_util.h" +using app::ViewProp; + namespace views { // Property used to indicate the HWND supports having mouse wheel messages // rerouted to it. -static const wchar_t* const kHWNDSupportMouseWheelRerouting = - L"__HWND_MW_REROUTE_OK"; +static const char* const kHWNDSupportMouseWheelRerouting = + "__HWND_MW_REROUTE_OK"; static bool WindowSupportsRerouteMouseWheel(HWND window) { while (GetWindowLong(window, GWL_STYLE) & WS_CHILD) { if (!IsWindow(window)) break; - if (reinterpret_cast<bool>(GetProp(window, - kHWNDSupportMouseWheelRerouting))) { + if (reinterpret_cast<bool>( + ViewProp::GetValue(window, kHWNDSupportMouseWheelRerouting))) { return true; } window = GetParent(window); @@ -53,9 +55,9 @@ static bool CanRedirectMouseWheelFrom(HWND window) { return true; } -app::win::ScopedProp* SetWindowSupportsRerouteMouseWheel(HWND hwnd) { - return new app::win::ScopedProp(hwnd, kHWNDSupportMouseWheelRerouting, - reinterpret_cast<HANDLE>(true)); +ViewProp* SetWindowSupportsRerouteMouseWheel(HWND hwnd) { + return new ViewProp(hwnd, kHWNDSupportMouseWheelRerouting, + reinterpret_cast<HANDLE>(true)); } bool RerouteMouseWheel(HWND window, WPARAM w_param, LPARAM l_param) { diff --git a/views/focus/focus_util_win.h b/views/focus/focus_util_win.h index 2c53c68..6394f5d 100644 --- a/views/focus/focus_util_win.h +++ b/views/focus/focus_util_win.h @@ -9,18 +9,16 @@ #include <windows.h> namespace app { -namespace win { -class ScopedProp; -} +class ViewProp; } namespace views { // Marks the passed |hwnd| as supporting mouse-wheel message rerouting. // We reroute the mouse wheel messages to such HWND when they are under the -// mouse pointer (but are not the active window). Callers must delete the -// returned object before the window is destroyed (see ScopedProp for details). -app::win::ScopedProp* SetWindowSupportsRerouteMouseWheel(HWND hwnd); +// mouse pointer (but are not the active window). Callers own the returned +// object. +app::ViewProp* SetWindowSupportsRerouteMouseWheel(HWND hwnd); // Forwards mouse wheel messages to the window under it. // Windows sends mouse wheel messages to the currently active window. diff --git a/views/widget/child_window_message_processor.cc b/views/widget/child_window_message_processor.cc index a3b578e..79a769d 100644 --- a/views/widget/child_window_message_processor.cc +++ b/views/widget/child_window_message_processor.cc @@ -4,24 +4,27 @@ #include "views/widget/child_window_message_processor.h" -#include "app/win/scoped_prop.h" +#include "app/view_prop.h" +#include "base/logging.h" + +#include "app/view_prop.h" namespace views { -static const wchar_t* kChildWindowKey = L"__CHILD_WINDOW_MESSAGE_PROCESSOR__"; +static const char* const kChildWindowKey = "__CHILD_WINDOW_MESSAGE_PROCESSOR__"; // static -app::win::ScopedProp* ChildWindowMessageProcessor::Register( +ViewProp* ChildWindowMessageProcessor::Register( HWND hwnd, ChildWindowMessageProcessor* processor) { DCHECK(processor); - return new app::win::ScopedProp(hwnd, kChildWindowKey, processor); + return new ViewProp(hwnd, kChildWindowKey, processor); } // static ChildWindowMessageProcessor* ChildWindowMessageProcessor::Get(HWND hwnd) { return reinterpret_cast<ChildWindowMessageProcessor*>( - ::GetProp(hwnd, kChildWindowKey)); + ViewProp::GetValue(hwnd, kChildWindowKey)); } } // namespace diff --git a/views/widget/child_window_message_processor.h b/views/widget/child_window_message_processor.h index 7d4e63e..3490864 100644 --- a/views/widget/child_window_message_processor.h +++ b/views/widget/child_window_message_processor.h @@ -9,9 +9,7 @@ #include <windows.h> namespace app { -namespace win { -class ScopedProp; -} +class ViewProp; } namespace views { @@ -25,8 +23,8 @@ class ChildWindowMessageProcessor { public: // Registers |processor| for |hwnd|. The caller takes ownership of the // returned object. - static app::win::ScopedProp* Register(HWND hwnd, - ChildWindowMessageProcessor* processor); + static app::ViewProp* Register(HWND hwnd, + ChildWindowMessageProcessor* processor); // Returns the ChildWindowMessageProcessor for |hwnd|, NULL if there isn't // one. diff --git a/views/widget/widget.h b/views/widget/widget.h index 3b33c90..968ec6a 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -207,9 +207,8 @@ class Widget { // Sets/Gets a native window property on the underlying native window object. // Returns NULL if the property does not exist. Setting the property value to // NULL removes the property. - virtual void SetNativeWindowProperty(const std::wstring& name, - void* value) = 0; - virtual void* GetNativeWindowProperty(const std::wstring& name) = 0; + virtual void SetNativeWindowProperty(const char* name, void* value) = 0; + virtual void* GetNativeWindowProperty(const char* name) = 0; // Gets the theme provider. virtual ThemeProvider* GetThemeProvider() const = 0; diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 5dea13c..dcb6fb3 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -32,7 +32,6 @@ namespace { // g_object data keys to associate a WidgetGtk object to a GtkWidget. const char* kWidgetKey = "__VIEWS_WIDGET__"; -const wchar_t* kWidgetWideKey = L"__VIEWS_WIDGET__"; // A g_object data key to associate a CompositePainter object to a GtkWidget. const char* kCompositePainterKey = "__VIEWS_COMPOSITE_PAINTER__"; // A g_object data key to associate the flag whether or not the widget @@ -803,13 +802,12 @@ const Window* WidgetGtk::GetWindow() const { return GetWindowImpl(widget_); } -void WidgetGtk::SetNativeWindowProperty(const std::wstring& name, - void* value) { - g_object_set_data(G_OBJECT(widget_), WideToUTF8(name).c_str(), value); +void WidgetGtk::SetNativeWindowProperty(const char* name, void* value) { + g_object_set_data(G_OBJECT(widget_), name, value); } -void* WidgetGtk::GetNativeWindowProperty(const std::wstring& name) { - return g_object_get_data(G_OBJECT(widget_), WideToUTF8(name).c_str()); +void* WidgetGtk::GetNativeWindowProperty(const char* name) { + return g_object_get_data(G_OBJECT(widget_), name); } ThemeProvider* WidgetGtk::GetThemeProvider() const { @@ -1490,7 +1488,7 @@ void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { } // Setting the WidgetKey property to widget_, which is used by // GetWidgetFromNativeWindow. - SetNativeWindowProperty(kWidgetWideKey, this); + SetNativeWindowProperty(kWidgetKey, this); } void WidgetGtk::ConfigureWidgetForTransparentBackground(GtkWidget* parent) { diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index 4135c86..a8a2947 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -186,9 +186,8 @@ class WidgetGtk virtual bool GetAccelerator(int cmd_id, menus::Accelerator* accelerator); virtual Window* GetWindow(); virtual const Window* GetWindow() const; - virtual void SetNativeWindowProperty(const std::wstring& name, - void* value); - virtual void* GetNativeWindowProperty(const std::wstring& name); + virtual void SetNativeWindowProperty(const char* name, void* value); + virtual void* GetNativeWindowProperty(const char* name); virtual ThemeProvider* GetThemeProvider() const; virtual ThemeProvider* GetDefaultThemeProvider() const; virtual FocusManager* GetFocusManager(); diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 77cf8c1..62643b2 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -7,8 +7,8 @@ #include "app/keyboard_code_conversion_win.h" #include "app/l10n_util_win.h" #include "app/system_monitor.h" +#include "app/view_prop.h" #include "app/win_util.h" -#include "app/win/scoped_prop.h" #include "base/string_util.h" #include "base/win_util.h" #include "gfx/canvas_skia.h" @@ -26,11 +26,15 @@ #include "views/widget/widget_delegate.h" #include "views/window/window_win.h" +using app::ViewProp; + namespace views { // Property used to link the HWND to its RootView. -static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__"; -static const wchar_t* kWidgetKey = L"__VIEWS_WIDGET__"; +static const char* const kRootViewWindowProperty = "__ROOT_VIEW__"; + +// Links the HWND to it's Widget (as a Widget, not a WidgetWin). +static const char* const kWidgetKey = "__VIEWS_WIDGET__"; bool WidgetWin::screen_reader_active_ = false; @@ -39,7 +43,8 @@ bool WidgetWin::screen_reader_active_ = false; #define OBJID_CUSTOM 1 RootView* GetRootViewForHWND(HWND hwnd) { - return reinterpret_cast<RootView*>(::GetProp(hwnd, kRootViewWindowProperty)); + return reinterpret_cast<RootView*>( + ViewProp::GetValue(hwnd, kRootViewWindowProperty)); } /////////////////////////////////////////////////////////////////////////////// @@ -414,21 +419,21 @@ const Window* WidgetWin::GetWindow() const { return GetWindowImpl(hwnd()); } -void WidgetWin::SetNativeWindowProperty(const std::wstring& name, void* value) { +void WidgetWin::SetNativeWindowProperty(const char* name, void* value) { // Remove the existing property (if any). - for (ScopedProps::iterator i = props_.begin(); i != props_.end(); ++i) { - if ((*i)->key() == name) { + for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { + if ((*i)->Key() == name) { props_.erase(i); break; } } if (value) - props_.push_back(new app::win::ScopedProp(hwnd(), name, value)); + props_.push_back(new ViewProp(hwnd(), name, value)); } -void* WidgetWin::GetNativeWindowProperty(const std::wstring& name) { - return GetProp(hwnd(), name.c_str()); +void* WidgetWin::GetNativeWindowProperty(const char* name) { + return ViewProp::GetValue(hwnd(), name); } ThemeProvider* WidgetWin::GetThemeProvider() const { @@ -1298,8 +1303,7 @@ Widget* Widget::CreatePopupWidget(TransparencyParam transparent, } static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { - RootView* root_view = - reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); + RootView* root_view = GetRootViewForHWND(hwnd); if (root_view) { *reinterpret_cast<RootView**>(l_param) = root_view; return FALSE; // Stop enumerating. @@ -1309,8 +1313,7 @@ static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) { // static RootView* Widget::FindRootView(HWND hwnd) { - RootView* root_view = - reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); + RootView* root_view = GetRootViewForHWND(hwnd); if (root_view) return root_view; @@ -1323,8 +1326,7 @@ RootView* Widget::FindRootView(HWND hwnd) { // Enumerate child windows as they could have RootView distinct from // the HWND's root view. BOOL CALLBACK EnumAllRootViewsChildProc(HWND hwnd, LPARAM l_param) { - RootView* root_view = - reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty)); + RootView* root_view = GetRootViewForHWND(hwnd); if (root_view) { std::set<RootView*>* root_views_set = reinterpret_cast<std::set<RootView*>*>(l_param); @@ -1335,8 +1337,7 @@ BOOL CALLBACK EnumAllRootViewsChildProc(HWND hwnd, LPARAM l_param) { void Widget::FindAllRootViews(HWND window, std::vector<RootView*>* root_views) { - RootView* root_view = - reinterpret_cast<RootView*>(GetProp(window, kRootViewWindowProperty)); + RootView* root_view = GetRootViewForHWND(window); std::set<RootView*> root_views_set; if (root_view) root_views_set.insert(root_view); @@ -1356,12 +1357,9 @@ void Widget::FindAllRootViews(HWND window, // static Widget* Widget::GetWidgetFromNativeView(gfx::NativeView native_view) { - if (IsWindow(native_view)) { - HANDLE raw_widget = GetProp(native_view, kWidgetKey); - if (raw_widget) - return reinterpret_cast<Widget*>(raw_widget); - } - return NULL; + return IsWindow(native_view) ? + reinterpret_cast<Widget*>(ViewProp::GetValue(native_view, kWidgetKey)) : + NULL; } // static diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index bfb9137..8b85e47 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -23,9 +23,7 @@ #include "views/widget/widget.h" namespace app { -namespace win { -class ScopedProp; -} +class ViewProp; } namespace gfx { @@ -234,9 +232,8 @@ class WidgetWin : public gfx::WindowImpl, virtual bool GetAccelerator(int cmd_id, menus::Accelerator* accelerator); virtual Window* GetWindow(); virtual const Window* GetWindow() const; - virtual void SetNativeWindowProperty(const std::wstring& name, - void* value); - virtual void* GetNativeWindowProperty(const std::wstring& name); + virtual void SetNativeWindowProperty(const char* name, void* value); + virtual void* GetNativeWindowProperty(const char* name); virtual ThemeProvider* GetThemeProvider() const; virtual ThemeProvider* GetDefaultThemeProvider() const; virtual FocusManager* GetFocusManager(); @@ -487,7 +484,7 @@ class WidgetWin : public gfx::WindowImpl, bool is_window_; private: - typedef ScopedVector<app::win::ScopedProp> ScopedProps; + typedef ScopedVector<app::ViewProp> ViewProps; // Implementation of GetWindow. Ascends the parents of |hwnd| returning the // first ancestor that is a Window. @@ -595,7 +592,7 @@ class WidgetWin : public gfx::WindowImpl, // we always mod this value with the max view events above . int accessibility_view_events_index_; - ScopedProps props_; + ViewProps props_; DISALLOW_COPY_AND_ASSIGN(WidgetWin); }; |