summaryrefslogtreecommitdiffstats
path: root/views/controls/separator.cc
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-01 23:15:45 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-01 23:15:45 +0000
commitfa922b17ac56895da698ca72726e706948980960 (patch)
tree6cc1889000b443a15bfce8c9356794a10aa30dde /views/controls/separator.cc
parentfc1ae90b61e9c3969e2df93d4e6e06c3efe4f9b8 (diff)
downloadchromium_src-fa922b17ac56895da698ca72726e706948980960.zip
chromium_src-fa922b17ac56895da698ca72726e706948980960.tar.gz
chromium_src-fa922b17ac56895da698ca72726e706948980960.tar.bz2
Make separator portable. Simpler than other native controls so no wrapper interface.
TEST=none BUG=none Review URL: http://codereview.chromium.org/118065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17368 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/separator.cc')
-rw-r--r--views/controls/separator.cc93
1 files changed, 80 insertions, 13 deletions
diff --git a/views/controls/separator.cc b/views/controls/separator.cc
index af0962f..0e468d9 100644
--- a/views/controls/separator.cc
+++ b/views/controls/separator.cc
@@ -1,14 +1,61 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2009 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 "views/controls/separator.h"
-#include "views/controls/native/native_view_host.h"
+#if defined(OS_LINUX)
+#include "views/controls/native_control_gtk.h"
+#elif defined(OS_WIN)
+#include "views/controls/native_control_win.h"
+#endif
+#include "views/widget/widget.h"
namespace views {
-static const int kSeparatorSize = 2;
+#if defined(OS_WIN)
+class NativeSeparatorWin : public NativeControlWin {
+ public:
+ explicit NativeSeparatorWin(Separator* separator) : separator_(separator) {}
+ virtual ~NativeSeparatorWin() {}
+
+ // Overridden from NativeControlWin:
+ virtual void CreateNativeControl() {
+ HWND control_hwnd = CreateWindowEx(GetAdditionalExStyle(), L"STATIC", L"",
+ WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN,
+ 0, 0, width(), height(),
+ separator_->GetWidget()->GetNativeView(),
+ NULL, NULL, NULL);
+ NativeControlCreated(control_hwnd);
+ }
+
+ private:
+ Separator* separator_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeSeparatorWin);
+};
+#elif defined(OS_LINUX)
+class NativeSeparatorGtk : public NativeControlGtk {
+ public:
+ explicit NativeSeparatorGtk(Separator* separator) : separator_(separator) {}
+ virtual ~NativeSeparatorGtk() {}
+
+ // Overridden from NativeSeparatorGtk:
+ virtual void CreateNativeControl() {
+ // TODO(port): create a separator widget and pass to NativeControlCreated.
+ }
+
+ private:
+ Separator* separator_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeSeparatorGtk);
+};
+#endif
+
+// static
+const char Separator::kViewClassName[] = "views/Separator";
+
+const int kSeparatorSize = 2;
Separator::Separator() {
SetFocusable(false);
@@ -17,21 +64,41 @@ Separator::Separator() {
Separator::~Separator() {
}
-HWND Separator::CreateNativeControl(HWND parent_container) {
- SetFixedHeight(kSeparatorSize, CENTER);
+////////////////////////////////////////////////////////////////////////////////
+// Separator, View overrides:
- return ::CreateWindowEx(GetAdditionalExStyle(), L"STATIC", L"",
- WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN,
- 0, 0, width(), height(),
- parent_container, NULL, NULL, NULL);
+gfx::Size Separator::GetPreferredSize() {
+ return gfx::Size(width(), kSeparatorSize);
}
-LRESULT Separator::OnNotify(int w_param, LPNMHDR l_param) {
- return 0;
+void Separator::Layout() {
+ if (native_wrapper_) {
+ native_wrapper_->SetBounds(0, 0, width(), height());
+ native_wrapper_->Layout();
+ }
}
-gfx::Size Separator::GetPreferredSize() {
- return gfx::Size(width(), fixed_height_);
+void Separator::ViewHierarchyChanged(bool is_add, View* parent,
+ View* child) {
+ if (is_add && !native_wrapper_ && GetWidget()) {
+ CreateNativeWrapper();
+ AddChildView(native_wrapper_);
+ }
+}
+
+std::string Separator::GetClassName() const {
+ return kViewClassName;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Separator, private:
+
+void Separator::CreateNativeWrapper() {
+#if defined(OS_WIN)
+ native_wrapper_ = new NativeSeparatorWin(this);
+#elif defined(OS_LINUX)
+ native_wrapper_ = new NativeSeparatorGtk(this);
+#endif
}
} // namespace views