summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/app.gyp2
-rw-r--r--app/app_base.gypi4
-rw-r--r--app/view_prop.cc106
-rw-r--r--app/view_prop.h47
-rw-r--r--app/view_prop_unittest.cc70
-rw-r--r--app/win/scoped_prop.h6
-rw-r--r--chrome/browser/external_tab_container_win.cc20
-rw-r--r--chrome/browser/external_tab_container_win.h6
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_win.cc31
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_win.h6
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc17
-rw-r--r--views/accessibility/view_accessibility.cc11
-rw-r--r--views/accessibility/view_accessibility.h2
-rw-r--r--views/controls/native_control.cc15
-rw-r--r--views/controls/native_control_win.cc13
-rw-r--r--views/controls/native_control_win.h8
-rw-r--r--views/focus/focus_util_win.cc18
-rw-r--r--views/focus/focus_util_win.h10
-rw-r--r--views/widget/child_window_message_processor.cc13
-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
25 files changed, 138 insertions, 356 deletions
diff --git a/app/app.gyp b/app/app.gyp
index ce64955..2c8e7f7 100644
--- a/app/app.gyp
+++ b/app/app.gyp
@@ -56,7 +56,6 @@
'text_elider_unittest.cc',
'tree_node_iterator_unittest.cc',
'tree_node_model_unittest.cc',
- 'view_prop_unittest.cc',
'win_util_unittest.cc',
],
'include_dirs': [
@@ -76,7 +75,6 @@
['OS!="win"', {
'sources!': [
'os_exchange_data_win_unittest.cc',
- 'view_prop_unittest.cc',
'win_util_unittest.cc',
],
}],
diff --git a/app/app_base.gypi b/app/app_base.gypi
index a121a50..37e0640 100644
--- a/app/app_base.gypi
+++ b/app/app_base.gypi
@@ -221,8 +221,6 @@
'throb_animation.h',
'tween.cc',
'tween.h',
- 'view_prop.cc',
- 'view_prop.h',
'win/drag_source.cc',
'win/drag_source.h',
'win/drop_target.cc',
@@ -317,8 +315,6 @@
'gfx/native_theme_win.cc',
'gfx/native_theme_win.h',
'os_exchange_data.cc',
- 'view_prop.cc',
- 'view_prop.h',
'win/iat_patch_function.cc',
'win/iat_patch_function.h',
],
diff --git a/app/view_prop.cc b/app/view_prop.cc
deleted file mode 100644
index 778f381..0000000
--- a/app/view_prop.cc
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "app/view_prop.h"
-
-#include <set>
-
-namespace app {
-namespace win {
-
-// Maints the actual view, key and data.
-class ViewProp::Data : public base::RefCounted<ViewProp::Data> {
- public:
- // Returns the Data* for the view/key pair. If |create| is false and |Get|
- // has not been invoked for the view/key pair, NULL is returned.
- static void Get(gfx::NativeView view,
- const char* key,
- bool create,
- scoped_refptr<Data>* data) {
- if (!data_set_)
- data_set_ = new DataSet;
- scoped_refptr<Data> new_data(new Data(view, key));
- DataSet::const_iterator i = data_set_->find(new_data.get());
- if (i != data_set_->end()) {
- *data = *i;
- return;
- }
- if (!create)
- return;
- data_set_->insert(new_data.get());
- *data = new_data.get();
- }
-
- // The data.
- void set_data(void* data) { data_ = data; }
- void* data() const { return data_; }
-
- const char* key() const { return key_; }
-
- private:
- friend class base::RefCounted<Data>;
-
- // Used to order the Data in the map.
- class DataComparator {
- public:
- bool operator()(const Data* d1, const Data* d2) const {
- return (d1->view_ == d2->view_) ? (d1->key_ < d2->key_) :
- (d1->view_ < d2->view_);
- }
- };
-
- typedef std::set<Data*, DataComparator> DataSet;
-
- Data(gfx::NativeView view, const char* key)
- : view_(view),
- key_(key),
- data_(NULL) {}
-
- ~Data() {
- DataSet::iterator i = data_set_->find(this);
- // Also check for equality using == as |Get| creates dummy values in order
- // to look up a value.
- if (i != data_set_->end() && *i == this)
- data_set_->erase(i);
- }
-
- // The existing set of Data is stored here. ~Data removes from the set.
- static DataSet* data_set_;
-
- const gfx::NativeView view_;
- const char* key_;
- void* data_;
-
- DISALLOW_COPY_AND_ASSIGN(Data);
-};
-
-// static
-ViewProp::Data::DataSet* ViewProp::Data::data_set_ = NULL;
-
-ViewProp::ViewProp(gfx::NativeView view, const char* key, void* data) {
- Data::Get(view, key, true, &data_);
- data_->set_data(data);
-}
-
-ViewProp::~ViewProp() {
- // This is done to provide similar semantics to SetProp. In particular it's
- // assumed that ~ViewProp should behave as though RemoveProp was invoked.
- data_->set_data(NULL);
-}
-
-// static
-void* ViewProp::GetValue(gfx::NativeView view, const char* key) {
- scoped_refptr<Data> data;
- Data::Get(view, key, false, &data);
- return data.get() ? data->data() : NULL;
-}
-
-// static
-const char* ViewProp::Key() const {
- return data_->key();
-}
-
-} // namespace win
-
-} // namespace app
diff --git a/app/view_prop.h b/app/view_prop.h
deleted file mode 100644
index c319460..0000000
--- a/app/view_prop.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef APP_VIEW_PROP_H_
-#define APP_VIEW_PROP_H_
-#pragma once
-
-#include "base/basictypes.h"
-#include "base/ref_counted.h"
-#include "gfx/native_widget_types.h"
-
-namespace app {
-
-// ViewProp maintains a key/value pair for a particular view. ViewProp is
-// designed as a replacement for the Win32's SetProp, but does not make use of
-// window manager memory. ViewProp shares similar semantics as SetProp, the
-// value for a particular view/key pair comes from the last ViewProp created.
-class ViewProp {
- public:
- // Associates data with a view/key pair. If a ViewProp has already been
- // created for the specified pair |data| replaces the current value.
- //
- // ViewProp does *not* make a copy of the char*, the pointer is used for
- // sorting.
- ViewProp(gfx::NativeView view, const char* key, void* data);
- ~ViewProp();
-
- // Returns the value associated with the view/key pair, or NULL if there is
- // none.
- static void* GetValue(gfx::NativeView view, const char* key);
-
- // Returns the key.
- const char* Key() const;
-
- private:
- class Data;
-
- // Stores the actual data.
- scoped_refptr<Data> data_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewProp);
-};
-
-} // namespace app
-
-#endif // APP_VIEW_PROP_H_
diff --git a/app/view_prop_unittest.cc b/app/view_prop_unittest.cc
deleted file mode 100644
index 9b81cd5..0000000
--- a/app/view_prop_unittest.cc
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-#include "app/view_prop.h"
-#include "base/scoped_ptr.h"
-
-typedef testing::Test ViewPropTest;
-
-static const char* kKey1 = "key_1";
-static const char* kKey2 = "key_2";
-
-using app::ViewProp;
-
-// Test a handful of viewprop assertions.
-TEST_F(ViewPropTest, Basic) {
- gfx::NativeView nv1 = reinterpret_cast<gfx::NativeView>(1);
- gfx::NativeView nv2 = reinterpret_cast<gfx::NativeView>(2);
-
- void* data1 = reinterpret_cast<void*>(11);
- void* data2 = reinterpret_cast<void*>(12);
-
- // Initial value for a new view/key pair should be NULL.
- EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
-
- {
- // Register a value for a view/key pair.
- ViewProp prop(nv1, kKey1, data1);
- EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1));
- }
-
- // The property fell out of scope, so the value should now be NULL.
- EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
-
- {
- // Register a value for a view/key pair.
- scoped_ptr<ViewProp> v1(new ViewProp(nv1, kKey1, data1));
- EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1));
-
- // Register a value for the same view/key pair.
- scoped_ptr<ViewProp> v2(new ViewProp(nv1, kKey1, data2));
- // The new value should take over.
- EXPECT_EQ(data2, ViewProp::GetValue(nv1, kKey1));
-
- // Null out the first ViewProp, which should NULL out the value.
- v1.reset(NULL);
- EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
- }
-
- // The property fell out of scope, so the value should now be NULL.
- EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
-
- {
- // Register a value for a view/key pair.
- scoped_ptr<ViewProp> v1(new ViewProp(nv1, kKey1, data1));
- scoped_ptr<ViewProp> v2(new ViewProp(nv2, kKey2, data2));
- EXPECT_EQ(data1, ViewProp::GetValue(nv1, kKey1));
- EXPECT_EQ(data2, ViewProp::GetValue(nv2, kKey2));
-
- v1.reset(NULL);
- EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
- EXPECT_EQ(data2, ViewProp::GetValue(nv2, kKey2));
-
- v2.reset(NULL);
- EXPECT_EQ(NULL, ViewProp::GetValue(nv1, kKey1));
- EXPECT_EQ(NULL, ViewProp::GetValue(nv2, kKey2));
- }
-}
diff --git a/app/win/scoped_prop.h b/app/win/scoped_prop.h
index c309e52..14e6a6a 100644
--- a/app/win/scoped_prop.h
+++ b/app/win/scoped_prop.h
@@ -18,12 +18,6 @@ namespace win {
// cleanup. ScopedProp must be destroyed before the window is destroyed, else
// you're going to leak a property, which could lead to failure to set a
// property later on.
-//
-// *WARNING*
-// SetProp is very fragile. SetProp makes use of a finite chunk of memory that
-// is very easy to exhaust. Unless you need to share a property across process
-// boundaries you should instead use ViewProp, which does not cause leaks at the
-// window manager.
class ScopedProp {
public:
// Registers the key value pair for the specified window. ScopedProp does not
diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc
index a248db2..41b0a99 100644
--- a/chrome/browser/external_tab_container_win.cc
+++ b/chrome/browser/external_tab_container_win.cc
@@ -7,7 +7,7 @@
#include <string>
#include "app/l10n_util.h"
-#include "app/view_prop.h"
+#include "app/win/scoped_prop.h"
#include "base/debug/trace_event.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
@@ -47,9 +47,7 @@
#include "views/widget/root_view.h"
#include "views/window/window.h"
-using app::ViewProp;
-
-static const char kWindowObjectKey[] = "ChromeWindowObject";
+static const wchar_t kWindowObjectKey[] = L"ChromeWindowObject";
// This class overrides the LinkActivated function in the PageInfoBubbleView
// class and routes the help center link navigation to the host browser.
@@ -136,7 +134,8 @@ bool ExternalTabContainer::Init(Profile* profile,
// TODO(jcampan): limit focus traversal to contents.
- prop_.reset(new ViewProp(GetNativeView(), kWindowObjectKey, this));
+ prop_.reset(
+ new app::win::ScopedProp(GetNativeView(), kWindowObjectKey, this));
if (existing_contents) {
tab_contents_ = existing_contents;
@@ -285,7 +284,10 @@ void ExternalTabContainer::FocusThroughTabTraversal(
// static
bool ExternalTabContainer::IsExternalTabContainer(HWND window) {
- return ViewProp::GetValue(window, kWindowObjectKey) != NULL;
+ if (::GetProp(window, kWindowObjectKey) != NULL)
+ return true;
+
+ return false;
}
// static
@@ -299,7 +301,7 @@ ExternalTabContainer* ExternalTabContainer::GetContainerForTab(
return NULL;
}
ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>(
- ViewProp::GetValue(parent_window, kWindowObjectKey));
+ GetProp(parent_window, kWindowObjectKey));
return container;
}
@@ -309,8 +311,8 @@ ExternalTabContainer*
gfx::NativeView native_window) {
ExternalTabContainer* tab_container = NULL;
if (native_window) {
- tab_container = reinterpret_cast<ExternalTabContainer*>(
- ViewProp::GetValue(native_window, kWindowObjectKey));
+ HANDLE handle = ::GetProp(native_window, kWindowObjectKey);
+ tab_container = reinterpret_cast<ExternalTabContainer*>(handle);
}
return tab_container;
}
diff --git a/chrome/browser/external_tab_container_win.h b/chrome/browser/external_tab_container_win.h
index cc0e35c..91ce11c 100644
--- a/chrome/browser/external_tab_container_win.h
+++ b/chrome/browser/external_tab_container_win.h
@@ -31,7 +31,9 @@ class TabContentsContainer;
class RenderViewContextMenuViews;
namespace app {
-class ViewProp;
+namespace win {
+class ScopedProp;
+}
}
namespace IPC {
@@ -337,7 +339,7 @@ class ExternalTabContainer : public TabContentsDelegate,
// page without chrome frame.
bool route_all_top_level_navigations_;
- scoped_ptr<app::ViewProp> prop_;
+ scoped_ptr<app::win::ScopedProp> prop_;
DISALLOW_COPY_AND_ASSIGN(ExternalTabContainer);
};
diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc
index 3f9b9b1..6945b2e 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_win.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc
@@ -7,7 +7,6 @@
#include "app/l10n_util.h"
#include "app/l10n_util_win.h"
#include "app/resource_bundle.h"
-#include "app/view_prop.h"
#include "app/win/scoped_prop.h"
#include "base/command_line.h"
#include "base/i18n/rtl.h"
@@ -52,7 +51,6 @@
#include "webkit/glue/webaccessibility.h"
#include "webkit/glue/webcursor.h"
-using app::ViewProp;
using base::TimeDelta;
using base::TimeTicks;
using WebKit::WebInputEvent;
@@ -73,7 +71,7 @@ const int kMaxTooltipLength = 1024;
// listening for MSAA events.
const int kIdCustom = 1;
-const char* const kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__";
+const wchar_t* kRenderWidgetHostViewKey = L"__RENDER_WIDGET_HOST_VIEW__";
// A callback function for EnumThreadWindows to enumerate and dismiss
// any owned popop windows
@@ -310,10 +308,9 @@ void RenderWidgetHostViewWin::CreateWnd(HWND parent) {
// Add a property indicating that a particular renderer is associated with
// this window. Used by the GPU process to validate window handles it
- // receives from renderer processes. As this is used by a separate process we
- // have to use ScopedProp here instead of ViewProp.
+ // receives from renderer processes.
int renderer_id = render_widget_host_->process()->id();
- renderer_id_prop_.reset(
+ props_.push_back(
new app::win::ScopedProp(m_hWnd,
chrome::kChromiumRendererIdProperty,
reinterpret_cast<HANDLE>(renderer_id)));
@@ -801,11 +798,12 @@ LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) {
props_.push_back(views::SetWindowSupportsRerouteMouseWheel(m_hWnd));
// Save away our HWND in the parent window as a property so that the
// accessibility code can find it.
- props_.push_back(new ViewProp(GetParent(),
- kViewsNativeHostPropForAccessibility,
- m_hWnd));
- props_.push_back(new ViewProp(m_hWnd, kRenderWidgetHostViewKey,
- static_cast<RenderWidgetHostView*>(this)));
+ props_.push_back(new app::win::ScopedProp(
+ GetParent(), kViewsNativeHostPropForAccessibility,
+ m_hWnd));
+ props_.push_back(new app::win::ScopedProp(
+ m_hWnd, kRenderWidgetHostViewKey,
+ static_cast<RenderWidgetHostView*>(this)));
return 0;
}
@@ -836,7 +834,6 @@ void RenderWidgetHostViewWin::OnDestroy() {
// sequence as part of the usual cleanup when the plugin instance goes away.
EnumChildWindows(m_hWnd, DetachPluginWindowsCallback, NULL);
- renderer_id_prop_.reset();
props_.reset();
ResetTooltip();
@@ -1638,7 +1635,11 @@ void RenderWidgetHostViewWin::ShutdownHost() {
RenderWidgetHostView*
RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView(
gfx::NativeView native_view) {
- return ::IsWindow(native_view) ?
- reinterpret_cast<RenderWidgetHostView*>(
- ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL;
+ if (::IsWindow(native_view)) {
+ HANDLE raw_render_host_view = ::GetProp(native_view,
+ kRenderWidgetHostViewKey);
+ if (raw_render_host_view)
+ return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view);
+ }
+ return NULL;
}
diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.h b/chrome/browser/renderer_host/render_widget_host_view_win.h
index 13609e6..d02193f 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_win.h
+++ b/chrome/browser/renderer_host/render_widget_host_view_win.h
@@ -25,9 +25,6 @@
#include "webkit/glue/webcursor.h"
namespace app {
-
-class ViewProp;
-
namespace win {
class ScopedProp;
}
@@ -343,8 +340,7 @@ class RenderWidgetHostViewWin
// method.
WebKit::WebTextInputType text_input_type_;
- ScopedVector<app::ViewProp> props_;
- scoped_ptr<app::win::ScopedProp> renderer_id_prop_;
+ ScopedVector<app::win::ScopedProp> props_;
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewWin);
};
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 1c5c5ee..4552de4 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -82,7 +82,6 @@
#include "views/window/window.h"
#if defined(OS_WIN)
-#include "app/view_prop.h"
#include "app/win_util.h"
#include "chrome/browser/aeropeek_manager.h"
#include "chrome/browser/jumplist_win.h"
@@ -100,7 +99,11 @@ using views::GridLayout;
static const int kStatusBubbleHeight = 20;
// The name of a key to store on the window handle so that other code can
// locate this object using just the handle.
-static const char* const kBrowserViewKey = "__BROWSER_VIEW__";
+#if defined(OS_WIN)
+static const wchar_t* kBrowserViewKey = L"__BROWSER_VIEW__";
+#else
+static const char* kBrowserViewKey = "__BROWSER_VIEW__";
+#endif
// How frequently we check for hung plugin windows.
static const int kDefaultHungPluginDetectFrequency = 2000;
// How long do we wait before we consider a window hung (in ms).
@@ -483,8 +486,9 @@ BrowserView* BrowserView::GetBrowserViewForNativeWindow(
gfx::NativeWindow window) {
#if defined(OS_WIN)
if (IsWindow(window)) {
- return reinterpret_cast<BrowserView*>(
- app::ViewProp::GetValue(window, kBrowserViewKey));
+ HANDLE data = GetProp(window, kBrowserViewKey);
+ if (data)
+ return reinterpret_cast<BrowserView*>(data);
}
#else
if (window) {
@@ -1885,7 +1889,12 @@ void BrowserView::Init() {
SetLayoutManager(CreateLayoutManager());
// Stow a pointer to this object onto the window handle so that we can get
// at it later when all we have is a native view.
+#if defined(OS_WIN)
GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this);
+#else
+ g_object_set_data(G_OBJECT(GetWidget()->GetNativeView()),
+ kBrowserViewKey, this);
+#endif
// Start a hung plugin window detector for this browser object (as long as
// hang detection is not disabled).
diff --git a/views/accessibility/view_accessibility.cc b/views/accessibility/view_accessibility.cc
index 5d51d814..c092895 100644
--- a/views/accessibility/view_accessibility.cc
+++ b/views/accessibility/view_accessibility.cc
@@ -4,12 +4,11 @@
#include "views/accessibility/view_accessibility.h"
-#include "app/view_prop.h"
#include "views/widget/widget.h"
#include "views/widget/widget_win.h"
-const char kViewsNativeHostPropForAccessibility[] =
- "Views_NativeViewHostHWNDForAccessibility";
+const wchar_t kViewsNativeHostPropForAccessibility[] =
+ L"Views_NativeViewHostHWNDForAccessibility";
// static
scoped_refptr<ViewAccessibility> ViewAccessibility::Create(views::View* view) {
@@ -711,9 +710,9 @@ HRESULT ViewAccessibility::GetNativeIAccessibleInterface(
if (!native_host || !accessible)
return E_INVALIDARG;
- HWND native_view_window = static_cast<HWND>(
- app::ViewProp::GetValue(native_host->native_view(),
- kViewsNativeHostPropForAccessibility));
+ HWND native_view_window =
+ static_cast<HWND>(GetProp(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 66df163c..9803cba 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 char kViewsNativeHostPropForAccessibility[];
+extern const wchar_t kViewsNativeHostPropForAccessibility[];
#endif // VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_H_
diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc
index 13881bb..ef719c9 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/view_prop.h"
+#include "app/win/scoped_prop.h"
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "base/win_util.h"
@@ -24,12 +24,10 @@
#include "views/focus/focus_manager.h"
#include "views/widget/widget.h"
-using app::ViewProp;
-
namespace views {
// Maps to the NativeControl.
-static const char* const kNativeControlKey = "__NATIVE_CONTROL__";
+static const wchar_t* const kNativeControlKey = L"__NATIVE_CONTROL__";
class NativeControlContainer : public CWindowImpl<NativeControlContainer,
CWindow,
@@ -91,7 +89,8 @@ 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 ViewProp(control_, kNativeControlKey , parent_));
+ prop_.reset(
+ new app::win::ScopedProp(control_, kNativeControlKey , parent_));
::ShowWindow(control_, SW_SHOW);
return 1;
@@ -167,7 +166,7 @@ class NativeControlContainer : public CWindowImpl<NativeControlContainer,
// Message handler that was set before we reset it.
WNDPROC original_handler_;
- scoped_ptr<ViewProp> prop_;
+ scoped_ptr<app::win::ScopedProp> prop_;
DISALLOW_COPY_AND_ASSIGN(NativeControlContainer);
};
@@ -364,8 +363,8 @@ LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window,
UINT message,
WPARAM w_param,
LPARAM l_param) {
- NativeControl* native_control = static_cast<NativeControl*>(
- ViewProp::GetValue(window, kNativeControlKey));
+ NativeControl* native_control =
+ static_cast<NativeControl*>(GetProp(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 a223993..c4f811c 100644
--- a/views/controls/native_control_win.cc
+++ b/views/controls/native_control_win.cc
@@ -7,16 +7,14 @@
#include <windowsx.h>
#include "app/l10n_util_win.h"
-#include "app/view_prop.h"
+#include "app/win/scoped_prop.h"
#include "base/logging.h"
#include "base/win_util.h"
#include "views/focus/focus_manager.h"
-using app::ViewProp;
-
namespace views {
-static const char* const kNativeControlWinKey = "__NATIVE_CONTROL_WIN__";
+static const wchar_t* kNativeControlWinKey = L"__NATIVE_CONTROL_WIN__";
////////////////////////////////////////////////////////////////////////////////
// NativeControlWin, public:
@@ -132,7 +130,8 @@ 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 ViewProp(native_control, kNativeControlWinKey, this));
+ props_.push_back(
+ new app::win::ScopedProp(native_control, kNativeControlWinKey, this));
props_.push_back(ChildWindowMessageProcessor::Register(native_control, this));
// Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages.
@@ -197,8 +196,8 @@ LRESULT NativeControlWin::NativeControlWndProc(HWND window,
UINT message,
WPARAM w_param,
LPARAM l_param) {
- NativeControlWin* native_control = reinterpret_cast<NativeControlWin*>(
- ViewProp::GetValue(window, kNativeControlWinKey));
+ NativeControlWin* native_control =
+ static_cast<NativeControlWin*>(GetProp(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 d27efa4..3733a15 100644
--- a/views/controls/native_control_win.h
+++ b/views/controls/native_control_win.h
@@ -13,7 +13,9 @@
#include "views/widget/child_window_message_processor.h"
namespace app {
-class ViewProp;
+namespace win {
+class ScopedProp;
+}
}
namespace views {
@@ -73,7 +75,7 @@ class NativeControlWin : public ChildWindowMessageProcessor,
DWORD GetAdditionalRTLStyle() const;
private:
- typedef ScopedVector<app::ViewProp> ViewProps;
+ typedef ScopedVector<app::win::ScopedProp> ScopedProps;
// 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
@@ -89,7 +91,7 @@ class NativeControlWin : public ChildWindowMessageProcessor,
// The window procedure before we subclassed.
WNDPROC original_wndproc_;
- ViewProps props_;
+ ScopedProps props_;
DISALLOW_COPY_AND_ASSIGN(NativeControlWin);
};
diff --git a/views/focus/focus_util_win.cc b/views/focus/focus_util_win.cc
index 23172ad..266a891 100644
--- a/views/focus/focus_util_win.cc
+++ b/views/focus/focus_util_win.cc
@@ -6,26 +6,24 @@
#include <windowsx.h>
-#include "app/view_prop.h"
+#include "app/win/scoped_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 char* const kHWNDSupportMouseWheelRerouting =
- "__HWND_MW_REROUTE_OK";
+static const wchar_t* const kHWNDSupportMouseWheelRerouting =
+ L"__HWND_MW_REROUTE_OK";
static bool WindowSupportsRerouteMouseWheel(HWND window) {
while (GetWindowLong(window, GWL_STYLE) & WS_CHILD) {
if (!IsWindow(window))
break;
- if (reinterpret_cast<bool>(
- ViewProp::GetValue(window, kHWNDSupportMouseWheelRerouting))) {
+ if (reinterpret_cast<bool>(GetProp(window,
+ kHWNDSupportMouseWheelRerouting))) {
return true;
}
window = GetParent(window);
@@ -55,9 +53,9 @@ static bool CanRedirectMouseWheelFrom(HWND window) {
return true;
}
-ViewProp* SetWindowSupportsRerouteMouseWheel(HWND hwnd) {
- return new ViewProp(hwnd, kHWNDSupportMouseWheelRerouting,
- reinterpret_cast<HANDLE>(true));
+app::win::ScopedProp* SetWindowSupportsRerouteMouseWheel(HWND hwnd) {
+ return new app::win::ScopedProp(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 6394f5d..2c53c68 100644
--- a/views/focus/focus_util_win.h
+++ b/views/focus/focus_util_win.h
@@ -9,16 +9,18 @@
#include <windows.h>
namespace app {
-class ViewProp;
+namespace win {
+class ScopedProp;
+}
}
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 own the returned
-// object.
-app::ViewProp* SetWindowSupportsRerouteMouseWheel(HWND hwnd);
+// 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);
// 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 79a769d..a3b578e 100644
--- a/views/widget/child_window_message_processor.cc
+++ b/views/widget/child_window_message_processor.cc
@@ -4,27 +4,24 @@
#include "views/widget/child_window_message_processor.h"
-#include "app/view_prop.h"
-#include "base/logging.h"
-
-#include "app/view_prop.h"
+#include "app/win/scoped_prop.h"
namespace views {
-static const char* const kChildWindowKey = "__CHILD_WINDOW_MESSAGE_PROCESSOR__";
+static const wchar_t* kChildWindowKey = L"__CHILD_WINDOW_MESSAGE_PROCESSOR__";
// static
-ViewProp* ChildWindowMessageProcessor::Register(
+app::win::ScopedProp* ChildWindowMessageProcessor::Register(
HWND hwnd,
ChildWindowMessageProcessor* processor) {
DCHECK(processor);
- return new ViewProp(hwnd, kChildWindowKey, processor);
+ return new app::win::ScopedProp(hwnd, kChildWindowKey, processor);
}
// static
ChildWindowMessageProcessor* ChildWindowMessageProcessor::Get(HWND hwnd) {
return reinterpret_cast<ChildWindowMessageProcessor*>(
- ViewProp::GetValue(hwnd, kChildWindowKey));
+ ::GetProp(hwnd, kChildWindowKey));
}
} // namespace
diff --git a/views/widget/child_window_message_processor.h b/views/widget/child_window_message_processor.h
index 3490864..7d4e63e 100644
--- a/views/widget/child_window_message_processor.h
+++ b/views/widget/child_window_message_processor.h
@@ -9,7 +9,9 @@
#include <windows.h>
namespace app {
-class ViewProp;
+namespace win {
+class ScopedProp;
+}
}
namespace views {
@@ -23,8 +25,8 @@ class ChildWindowMessageProcessor {
public:
// Registers |processor| for |hwnd|. The caller takes ownership of the
// returned object.
- static app::ViewProp* Register(HWND hwnd,
- ChildWindowMessageProcessor* processor);
+ static app::win::ScopedProp* 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 968ec6a..3b33c90 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -207,8 +207,9 @@ 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 char* name, void* value) = 0;
- virtual void* GetNativeWindowProperty(const char* name) = 0;
+ virtual void SetNativeWindowProperty(const std::wstring& name,
+ void* value) = 0;
+ virtual void* GetNativeWindowProperty(const std::wstring& 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 dcb6fb3..5dea13c 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -32,6 +32,7 @@ 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
@@ -802,12 +803,13 @@ const Window* WidgetGtk::GetWindow() const {
return GetWindowImpl(widget_);
}
-void WidgetGtk::SetNativeWindowProperty(const char* name, void* value) {
- g_object_set_data(G_OBJECT(widget_), name, value);
+void WidgetGtk::SetNativeWindowProperty(const std::wstring& name,
+ void* value) {
+ g_object_set_data(G_OBJECT(widget_), WideToUTF8(name).c_str(), value);
}
-void* WidgetGtk::GetNativeWindowProperty(const char* name) {
- return g_object_get_data(G_OBJECT(widget_), name);
+void* WidgetGtk::GetNativeWindowProperty(const std::wstring& name) {
+ return g_object_get_data(G_OBJECT(widget_), WideToUTF8(name).c_str());
}
ThemeProvider* WidgetGtk::GetThemeProvider() const {
@@ -1488,7 +1490,7 @@ void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) {
}
// Setting the WidgetKey property to widget_, which is used by
// GetWidgetFromNativeWindow.
- SetNativeWindowProperty(kWidgetKey, this);
+ SetNativeWindowProperty(kWidgetWideKey, this);
}
void WidgetGtk::ConfigureWidgetForTransparentBackground(GtkWidget* parent) {
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index a8a2947..4135c86 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -186,8 +186,9 @@ class WidgetGtk
virtual bool GetAccelerator(int cmd_id, menus::Accelerator* accelerator);
virtual Window* GetWindow();
virtual const Window* GetWindow() const;
- virtual void SetNativeWindowProperty(const char* name, void* value);
- virtual void* GetNativeWindowProperty(const char* name);
+ virtual void SetNativeWindowProperty(const std::wstring& name,
+ void* value);
+ virtual void* GetNativeWindowProperty(const std::wstring& 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 62643b2..77cf8c1 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,15 +26,11 @@
#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 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__";
+static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__";
+static const wchar_t* kWidgetKey = L"__VIEWS_WIDGET__";
bool WidgetWin::screen_reader_active_ = false;
@@ -43,8 +39,7 @@ bool WidgetWin::screen_reader_active_ = false;
#define OBJID_CUSTOM 1
RootView* GetRootViewForHWND(HWND hwnd) {
- return reinterpret_cast<RootView*>(
- ViewProp::GetValue(hwnd, kRootViewWindowProperty));
+ return reinterpret_cast<RootView*>(::GetProp(hwnd, kRootViewWindowProperty));
}
///////////////////////////////////////////////////////////////////////////////
@@ -419,21 +414,21 @@ const Window* WidgetWin::GetWindow() const {
return GetWindowImpl(hwnd());
}
-void WidgetWin::SetNativeWindowProperty(const char* name, void* value) {
+void WidgetWin::SetNativeWindowProperty(const std::wstring& name, void* value) {
// Remove the existing property (if any).
- for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) {
- if ((*i)->Key() == name) {
+ for (ScopedProps::iterator i = props_.begin(); i != props_.end(); ++i) {
+ if ((*i)->key() == name) {
props_.erase(i);
break;
}
}
if (value)
- props_.push_back(new ViewProp(hwnd(), name, value));
+ props_.push_back(new app::win::ScopedProp(hwnd(), name, value));
}
-void* WidgetWin::GetNativeWindowProperty(const char* name) {
- return ViewProp::GetValue(hwnd(), name);
+void* WidgetWin::GetNativeWindowProperty(const std::wstring& name) {
+ return GetProp(hwnd(), name.c_str());
}
ThemeProvider* WidgetWin::GetThemeProvider() const {
@@ -1303,7 +1298,8 @@ Widget* Widget::CreatePopupWidget(TransparencyParam transparent,
}
static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) {
- RootView* root_view = GetRootViewForHWND(hwnd);
+ RootView* root_view =
+ reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty));
if (root_view) {
*reinterpret_cast<RootView**>(l_param) = root_view;
return FALSE; // Stop enumerating.
@@ -1313,7 +1309,8 @@ static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM l_param) {
// static
RootView* Widget::FindRootView(HWND hwnd) {
- RootView* root_view = GetRootViewForHWND(hwnd);
+ RootView* root_view =
+ reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty));
if (root_view)
return root_view;
@@ -1326,7 +1323,8 @@ 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 = GetRootViewForHWND(hwnd);
+ RootView* root_view =
+ reinterpret_cast<RootView*>(GetProp(hwnd, kRootViewWindowProperty));
if (root_view) {
std::set<RootView*>* root_views_set =
reinterpret_cast<std::set<RootView*>*>(l_param);
@@ -1337,7 +1335,8 @@ BOOL CALLBACK EnumAllRootViewsChildProc(HWND hwnd, LPARAM l_param) {
void Widget::FindAllRootViews(HWND window,
std::vector<RootView*>* root_views) {
- RootView* root_view = GetRootViewForHWND(window);
+ RootView* root_view =
+ reinterpret_cast<RootView*>(GetProp(window, kRootViewWindowProperty));
std::set<RootView*> root_views_set;
if (root_view)
root_views_set.insert(root_view);
@@ -1357,9 +1356,12 @@ void Widget::FindAllRootViews(HWND window,
// static
Widget* Widget::GetWidgetFromNativeView(gfx::NativeView native_view) {
- return IsWindow(native_view) ?
- reinterpret_cast<Widget*>(ViewProp::GetValue(native_view, kWidgetKey)) :
- NULL;
+ if (IsWindow(native_view)) {
+ HANDLE raw_widget = GetProp(native_view, kWidgetKey);
+ if (raw_widget)
+ return reinterpret_cast<Widget*>(raw_widget);
+ }
+ return NULL;
}
// static
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 8b85e47..bfb9137 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -23,7 +23,9 @@
#include "views/widget/widget.h"
namespace app {
-class ViewProp;
+namespace win {
+class ScopedProp;
+}
}
namespace gfx {
@@ -232,8 +234,9 @@ 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 char* name, void* value);
- virtual void* GetNativeWindowProperty(const char* name);
+ virtual void SetNativeWindowProperty(const std::wstring& name,
+ void* value);
+ virtual void* GetNativeWindowProperty(const std::wstring& name);
virtual ThemeProvider* GetThemeProvider() const;
virtual ThemeProvider* GetDefaultThemeProvider() const;
virtual FocusManager* GetFocusManager();
@@ -484,7 +487,7 @@ class WidgetWin : public gfx::WindowImpl,
bool is_window_;
private:
- typedef ScopedVector<app::ViewProp> ViewProps;
+ typedef ScopedVector<app::win::ScopedProp> ScopedProps;
// Implementation of GetWindow. Ascends the parents of |hwnd| returning the
// first ancestor that is a Window.
@@ -592,7 +595,7 @@ class WidgetWin : public gfx::WindowImpl,
// we always mod this value with the max view events above .
int accessibility_view_events_index_;
- ViewProps props_;
+ ScopedProps props_;
DISALLOW_COPY_AND_ASSIGN(WidgetWin);
};