summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 23:10:18 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 23:10:18 +0000
commit601160029a2e7d6f4f634e9b26331f510449209b (patch)
tree2c655d1e53e73a196a8151428505bbd6d482d7b5 /views
parent24d692aa555b5673c3d6eb37252b6eec19f439b5 (diff)
downloadchromium_src-601160029a2e7d6f4f634e9b26331f510449209b.zip
chromium_src-601160029a2e7d6f4f634e9b26331f510449209b.tar.gz
chromium_src-601160029a2e7d6f4f634e9b26331f510449209b.tar.bz2
Adds a basic NativeWindowViews.
http://crbug.com/83663 TEST=none Review URL: http://codereview.chromium.org/7069022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86736 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/examples/examples_main.cc5
-rw-r--r--views/examples/native_window_views_example.cc91
-rw-r--r--views/examples/native_window_views_example.h32
-rw-r--r--views/views.gyp4
-rw-r--r--views/widget/native_widget_views.cc4
-rw-r--r--views/widget/native_widget_views.h1
-rw-r--r--views/window/native_window_gtk.cc3
-rw-r--r--views/window/native_window_views.cc171
-rw-r--r--views/window/native_window_views.h74
-rw-r--r--views/window/native_window_win.cc6
-rw-r--r--views/window/window.cc4
11 files changed, 388 insertions, 7 deletions
diff --git a/views/examples/examples_main.cc b/views/examples/examples_main.cc
index be25458..7e123aa 100644
--- a/views/examples/examples_main.cc
+++ b/views/examples/examples_main.cc
@@ -22,6 +22,7 @@
#include "views/examples/native_theme_button_example.h"
#include "views/examples/native_theme_checkbox_example.h"
#include "views/examples/native_widget_views_example.h"
+#include "views/examples/native_window_views_example.h"
#include "views/examples/radio_button_example.h"
#include "views/examples/scroll_view_example.h"
#include "views/examples/single_split_view_example.h"
@@ -115,6 +116,10 @@ void ExamplesMain::Run() {
tabbed_pane->AddTab(native_widget_views_example.GetExampleTitle(),
native_widget_views_example.GetExampleView());
+ examples::NativeWindowViewsExample native_window_views_example(this);
+ tabbed_pane->AddTab(native_window_views_example.GetExampleTitle(),
+ native_window_views_example.GetExampleView());
+
examples::TextfieldExample textfield_example(this);
tabbed_pane->AddTab(textfield_example.GetExampleTitle(),
textfield_example.GetExampleView());
diff --git a/views/examples/native_window_views_example.cc b/views/examples/native_window_views_example.cc
new file mode 100644
index 0000000..b5291de
--- /dev/null
+++ b/views/examples/native_window_views_example.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2011 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/examples/native_window_views_example.h"
+
+#include "ui/gfx/canvas.h"
+#include "views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/label.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+#include "views/window/native_window_views.h"
+#include "views/window/window.h"
+#include "views/window/window_delegate.h"
+
+namespace examples {
+
+class WindowContentView : public views::View,
+ public views::WindowDelegate,
+ public views::ButtonListener {
+ public:
+ WindowContentView()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(
+ button_(new views::TextButton(this, L"Click me!"))),
+ label_(new views::Label(L"Some label")) {
+ views::GridLayout* layout = new views::GridLayout(this);
+ views::ColumnSet* columns = layout->AddColumnSet(0);
+ columns->AddColumn(views::GridLayout::FILL,
+ views::GridLayout::FILL,
+ 1,
+ views::GridLayout::USE_PREF,
+ 0,
+ 0);
+ SetLayoutManager(layout);
+ layout->StartRow(0, 0);
+ layout->AddView(button_);
+ layout->StartRow(1, 0);
+ layout->AddView(label_);
+ }
+ virtual ~WindowContentView() {}
+
+ // Overridden from views::View:
+ virtual void OnPaint(gfx::Canvas* canvas) {
+ canvas->FillRectInt(SK_ColorWHITE, 0, 0, width(), height());
+ }
+
+ // Overridden from views::WindowDelegate:
+ virtual std::wstring GetWindowTitle() const {
+ return L"Example NativeWindowViews";
+ }
+ virtual View* GetContentsView() {
+ return this;
+ }
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
+ if (sender == button_)
+ label_->SetText(L"Button Clicked!");
+ }
+
+ private:
+ views::TextButton* button_;
+ views::Label* label_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowContentView);
+};
+
+NativeWindowViewsExample::NativeWindowViewsExample(ExamplesMain* main)
+ : ExampleBase(main) {
+}
+
+NativeWindowViewsExample::~NativeWindowViewsExample() {
+}
+
+std::wstring NativeWindowViewsExample::GetExampleTitle() {
+ return L"NativeWindowViews";
+}
+
+void NativeWindowViewsExample::CreateExampleView(views::View* container) {
+ views::Window* window = new views::Window;
+ views::NativeWindowViews* nwv =
+ new views::NativeWindowViews(container, window);
+ views::Window::InitParams params(new WindowContentView);
+ params.native_window = nwv;
+ params.widget_init_params.bounds = gfx::Rect(20, 20, 600, 300);
+ window->InitWindow(params);
+ window->Show();
+}
+
+} // namespace examples
diff --git a/views/examples/native_window_views_example.h b/views/examples/native_window_views_example.h
new file mode 100644
index 0000000..361fdf8
--- /dev/null
+++ b/views/examples/native_window_views_example.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2011 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 VIEWS_EXAMPLES_NATIVE_WINDOW_VIEWS_EXAMPLE_H_
+#define VIEWS_EXAMPLES_NATIVE_WINDOW_VIEWS_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "views/examples/example_base.h"
+
+namespace examples {
+
+class NativeWindowViewsExample : public ExampleBase {
+ public:
+ explicit NativeWindowViewsExample(ExamplesMain* main);
+ virtual ~NativeWindowViewsExample();
+
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle() OVERRIDE;
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NativeWindowViewsExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_NATIVE_WINDOW_VIEWS_EXAMPLE_H_
diff --git a/views/views.gyp b/views/views.gyp
index c45a3c9..781d857 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -388,6 +388,8 @@
'window/native_window_delegate.h',
'window/native_window_gtk.cc',
'window/native_window_gtk.h',
+ 'window/native_window_views.cc',
+ 'window/native_window_views.h',
'window/native_window_win.cc',
'window/native_window_win.h',
'window/non_client_view.cc',
@@ -579,6 +581,8 @@
'examples/native_theme_checkbox_example.h',
'examples/native_widget_views_example.cc',
'examples/native_widget_views_example.h',
+ 'examples/native_window_views_example.cc',
+ 'examples/native_window_views_example.h',
'examples/radio_button_example.cc',
'examples/radio_button_example.h',
'examples/scroll_view_example.cc',
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc
index 8e0df5a..bff9bde 100644
--- a/views/widget/native_widget_views.cc
+++ b/views/widget/native_widget_views.cc
@@ -27,6 +27,10 @@ View* NativeWidgetViews::GetView() {
return view_;
}
+const View* NativeWidgetViews::GetView() const {
+ return view_;
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews, NativeWidget implementation:
diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h
index c0d6a25..5089d59 100644
--- a/views/widget/native_widget_views.h
+++ b/views/widget/native_widget_views.h
@@ -26,6 +26,7 @@ class NativeWidgetViews : public NativeWidget {
// TODO(beng): remove.
View* GetView();
+ const View* GetView() const;
internal::NativeWidgetDelegate* delegate() { return delegate_; }
diff --git a/views/window/native_window_gtk.cc b/views/window/native_window_gtk.cc
index e54deb9..4e25fb4 100644
--- a/views/window/native_window_gtk.cc
+++ b/views/window/native_window_gtk.cc
@@ -11,7 +11,6 @@
#include "ui/gfx/rect.h"
#include "views/events/event.h"
#include "views/screen.h"
-#include "views/window/custom_frame_view.h"
#include "views/window/hit_test.h"
#include "views/window/native_window_delegate.h"
#include "views/window/non_client_view.h"
@@ -364,7 +363,7 @@ void NativeWindowGtk::SetUseDragFrame(bool use_drag_frame) {
}
NonClientFrameView* NativeWindowGtk::CreateFrameViewForWindow() {
- return new CustomFrameView(delegate_->AsWindow());
+ return NULL;
}
void NativeWindowGtk::SetAlwaysOnTop(bool always_on_top) {
diff --git a/views/window/native_window_views.cc b/views/window/native_window_views.cc
new file mode 100644
index 0000000..3957835
--- /dev/null
+++ b/views/window/native_window_views.cc
@@ -0,0 +1,171 @@
+// Copyright (c) 2011 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/window/native_window_views.h"
+
+#include "views/view.h"
+
+namespace views {
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeWindowViews, public:
+
+NativeWindowViews::NativeWindowViews(View* host,
+ internal::NativeWindowDelegate* delegate)
+ : NativeWidgetViews(host, delegate->AsNativeWidgetDelegate()),
+ delegate_(delegate) {
+}
+
+NativeWindowViews::~NativeWindowViews() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeWindowViews, NativeWindow implementation:
+
+Window* NativeWindowViews::GetWindow() {
+ return delegate_->AsWindow();
+}
+
+const Window* NativeWindowViews::GetWindow() const {
+ return delegate_->AsWindow();
+}
+
+NativeWidget* NativeWindowViews::AsNativeWidget() {
+ return this;
+}
+
+const NativeWidget* NativeWindowViews::AsNativeWidget() const {
+ return this;
+}
+
+gfx::Rect NativeWindowViews::GetRestoredBounds() const {
+ NOTIMPLEMENTED();
+ return GetView()->bounds();
+}
+
+void NativeWindowViews::ShowNativeWindow(ShowState state) {
+ NOTIMPLEMENTED();
+ GetView()->SetVisible(true);
+}
+
+void NativeWindowViews::BecomeModal() {
+ NOTIMPLEMENTED();
+}
+
+void NativeWindowViews::CenterWindow(const gfx::Size& size) {
+ // TODO(beng): actually center.
+ GetView()->SetBounds(0, 0, size.width(), size.height());
+}
+
+void NativeWindowViews::GetWindowBoundsAndMaximizedState(
+ gfx::Rect* bounds,
+ bool* maximized) const {
+ *bounds = GetView()->bounds();
+ *maximized = false;
+}
+
+void NativeWindowViews::EnableClose(bool enable) {
+}
+
+void NativeWindowViews::SetWindowTitle(const std::wstring& title) {
+}
+
+void NativeWindowViews::SetWindowIcons(const SkBitmap& window_icon,
+ const SkBitmap& app_icon) {
+}
+
+void NativeWindowViews::SetAccessibleName(const std::wstring& name) {
+}
+
+void NativeWindowViews::SetAccessibleRole(ui::AccessibilityTypes::Role role) {
+}
+
+void NativeWindowViews::SetAccessibleState(
+ ui::AccessibilityTypes::State state) {
+}
+
+void NativeWindowViews::SetWindowBounds(const gfx::Rect& bounds,
+ gfx::NativeWindow other_window) {
+ if (other_window)
+ NOTIMPLEMENTED();
+ GetView()->SetBoundsRect(bounds);
+}
+
+void NativeWindowViews::HideWindow() {
+ GetView()->SetVisible(false);
+}
+
+void NativeWindowViews::Activate() {
+ NOTIMPLEMENTED();
+}
+
+void NativeWindowViews::Deactivate() {
+ NOTIMPLEMENTED();
+}
+
+void NativeWindowViews::Maximize() {
+ NOTIMPLEMENTED();
+}
+
+void NativeWindowViews::Minimize() {
+ NOTIMPLEMENTED();
+}
+
+void NativeWindowViews::Restore() {
+ NOTIMPLEMENTED();
+}
+
+bool NativeWindowViews::IsActive() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool NativeWindowViews::IsVisible() const {
+ return GetView()->IsVisible();
+}
+
+bool NativeWindowViews::IsMaximized() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+bool NativeWindowViews::IsMinimized() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+void NativeWindowViews::SetFullscreen(bool fullscreen) {
+}
+
+bool NativeWindowViews::IsFullscreen() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+void NativeWindowViews::SetAlwaysOnTop(bool always_on_top) {
+}
+
+void NativeWindowViews::SetUseDragFrame(bool use_drag_frame) {
+}
+
+NonClientFrameView* NativeWindowViews::CreateFrameViewForWindow() {
+ return NULL;
+}
+
+void NativeWindowViews::UpdateFrameAfterFrameChange() {
+}
+
+gfx::NativeWindow NativeWindowViews::GetNativeWindow() const {
+ return NULL;
+}
+
+bool NativeWindowViews::ShouldUseNativeFrame() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+void NativeWindowViews::FrameTypeChanged() {
+}
+
+} // namespace views
diff --git a/views/window/native_window_views.h b/views/window/native_window_views.h
new file mode 100644
index 0000000..65a4310
--- /dev/null
+++ b/views/window/native_window_views.h
@@ -0,0 +1,74 @@
+// Copyright (c) 2011 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 VIEWS_WINDOW_NATIVE_WINDOW_VIEWS_H_
+#define VIEWS_WINDOW_NATIVE_WINDOW_VIEWS_H_
+#pragma once
+
+#include "base/message_loop.h"
+#include "views/window/native_window.h"
+#include "views/widget/native_widget_views.h"
+
+namespace views {
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeWindowViews
+//
+// A NativeWindow implementation that uses another View as its native widget.
+//
+class NativeWindowViews : public NativeWidgetViews,
+ public NativeWindow {
+ public:
+ NativeWindowViews(View* host, internal::NativeWindowDelegate* delegate);
+ virtual ~NativeWindowViews();
+
+ private:
+ // Overridden from NativeWindow:
+ virtual Window* GetWindow() OVERRIDE;
+ virtual const Window* GetWindow() const OVERRIDE;
+ virtual NativeWidget* AsNativeWidget() OVERRIDE;
+ virtual const NativeWidget* AsNativeWidget() const OVERRIDE;
+ virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
+ virtual void ShowNativeWindow(ShowState state) OVERRIDE;
+ virtual void BecomeModal() OVERRIDE;
+ virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
+ virtual void GetWindowBoundsAndMaximizedState(gfx::Rect* bounds,
+ bool* maximized) const OVERRIDE;
+ virtual void EnableClose(bool enable) OVERRIDE;
+ virtual void SetWindowTitle(const std::wstring& title) OVERRIDE;
+ virtual void SetWindowIcons(const SkBitmap& window_icon,
+ const SkBitmap& app_icon) OVERRIDE;
+ virtual void SetAccessibleName(const std::wstring& name) OVERRIDE;
+ virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE;
+ virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE;
+ virtual void SetWindowBounds(const gfx::Rect& bounds,
+ gfx::NativeWindow other_window) OVERRIDE;
+ virtual void HideWindow() OVERRIDE;
+ virtual void Activate() OVERRIDE;
+ virtual void Deactivate() OVERRIDE;
+ virtual void Maximize() OVERRIDE;
+ virtual void Minimize() OVERRIDE;
+ virtual void Restore() OVERRIDE;
+ virtual bool IsActive() const OVERRIDE;
+ virtual bool IsVisible() const OVERRIDE;
+ virtual bool IsMaximized() const OVERRIDE;
+ virtual bool IsMinimized() const OVERRIDE;
+ virtual void SetFullscreen(bool fullscreen) OVERRIDE;
+ virtual bool IsFullscreen() const OVERRIDE;
+ virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
+ virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE;
+ virtual NonClientFrameView* CreateFrameViewForWindow() OVERRIDE;
+ virtual void UpdateFrameAfterFrameChange() OVERRIDE;
+ virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
+ virtual bool ShouldUseNativeFrame() const OVERRIDE;
+ virtual void FrameTypeChanged() OVERRIDE;
+
+ internal::NativeWindowDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);
+};
+
+}
+
+#endif // VIEWS_WINDOW_NATIVE_WINDOW_VIEWS_H_
diff --git a/views/window/native_window_win.cc b/views/window/native_window_win.cc
index b7708d8..fed8173 100644
--- a/views/window/native_window_win.cc
+++ b/views/window/native_window_win.cc
@@ -22,7 +22,6 @@
#include "ui/gfx/path.h"
#include "views/accessibility/native_view_accessibility_win.h"
#include "views/window/client_view.h"
-#include "views/window/custom_frame_view.h"
#include "views/window/native_window_delegate.h"
#include "views/window/native_frame_view.h"
#include "views/window/non_client_view.h"
@@ -1308,9 +1307,8 @@ void NativeWindowWin::SetUseDragFrame(bool use_drag_frame) {
}
NonClientFrameView* NativeWindowWin::CreateFrameViewForWindow() {
- if (GetWindow()->ShouldUseNativeFrame())
- return new NativeFrameView(GetWindow());
- return new CustomFrameView(GetWindow());
+ return GetWindow()->ShouldUseNativeFrame() ?
+ new NativeFrameView(GetWindow()) : NULL;
}
void NativeWindowWin::UpdateFrameAfterFrameChange() {
diff --git a/views/window/window.cc b/views/window/window.cc
index 7af6bfa..f2d51ee 100644
--- a/views/window/window.cc
+++ b/views/window/window.cc
@@ -14,6 +14,7 @@
#include "ui/gfx/size.h"
#include "views/widget/widget.h"
#include "views/widget/native_widget.h"
+#include "views/window/custom_frame_view.h"
#include "views/window/native_window.h"
#include "views/window/window_delegate.h"
@@ -229,7 +230,8 @@ void Window::SetIsAlwaysOnTop(bool always_on_top) {
}
NonClientFrameView* Window::CreateFrameViewForWindow() {
- return native_window_->CreateFrameViewForWindow();
+ NonClientFrameView* frame_view = native_window_->CreateFrameViewForWindow();
+ return frame_view ? frame_view : new CustomFrameView(this);
}
void Window::UpdateFrameAfterFrameChange() {