summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-21 22:44:21 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-21 22:44:21 +0000
commit3b8a7f8e37e223f3cfbdb6893a3e372ba1e72bc2 (patch)
treedbcc9e25653efaa6d7b3fd0b646f56123f72f8f2 /views/widget
parent294b014b3743b8a359d423ab238d2ea2872cf629 (diff)
downloadchromium_src-3b8a7f8e37e223f3cfbdb6893a3e372ba1e72bc2.zip
chromium_src-3b8a7f8e37e223f3cfbdb6893a3e372ba1e72bc2.tar.gz
chromium_src-3b8a7f8e37e223f3cfbdb6893a3e372ba1e72bc2.tar.bz2
Attempt 2 at:
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 TEST=none TBR=cpu@chromium.org Review URL: http://codereview.chromium.org/5144005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66920 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/child_window_message_processor.cc11
-rw-r--r--views/widget/child_window_message_processor.h8
-rw-r--r--views/widget/widget.h5
-rw-r--r--views/widget/widget_gtk.cc12
-rw-r--r--views/widget/widget_gtk.h5
-rw-r--r--views/widget/widget_win.cc46
-rw-r--r--views/widget/widget_win.h13
7 files changed, 45 insertions, 55 deletions
diff --git a/views/widget/child_window_message_processor.cc b/views/widget/child_window_message_processor.cc
index a3b578e..7e94ea2 100644
--- a/views/widget/child_window_message_processor.cc
+++ b/views/widget/child_window_message_processor.cc
@@ -4,24 +4,25 @@
#include "views/widget/child_window_message_processor.h"
-#include "app/win/scoped_prop.h"
+#include "app/view_prop.h"
+#include "base/logging.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(
+app::ViewProp* ChildWindowMessageProcessor::Register(
HWND hwnd,
ChildWindowMessageProcessor* processor) {
DCHECK(processor);
- return new app::win::ScopedProp(hwnd, kChildWindowKey, processor);
+ return new app::ViewProp(hwnd, kChildWindowKey, processor);
}
// static
ChildWindowMessageProcessor* ChildWindowMessageProcessor::Get(HWND hwnd) {
return reinterpret_cast<ChildWindowMessageProcessor*>(
- ::GetProp(hwnd, kChildWindowKey));
+ app::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);
};