Commit 60116002 authored by ben@chromium.org's avatar ben@chromium.org

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
parent 24d692aa
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "views/examples/native_theme_button_example.h" #include "views/examples/native_theme_button_example.h"
#include "views/examples/native_theme_checkbox_example.h" #include "views/examples/native_theme_checkbox_example.h"
#include "views/examples/native_widget_views_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/radio_button_example.h"
#include "views/examples/scroll_view_example.h" #include "views/examples/scroll_view_example.h"
#include "views/examples/single_split_view_example.h" #include "views/examples/single_split_view_example.h"
...@@ -115,6 +116,10 @@ void ExamplesMain::Run() { ...@@ -115,6 +116,10 @@ void ExamplesMain::Run() {
tabbed_pane->AddTab(native_widget_views_example.GetExampleTitle(), tabbed_pane->AddTab(native_widget_views_example.GetExampleTitle(),
native_widget_views_example.GetExampleView()); 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); examples::TextfieldExample textfield_example(this);
tabbed_pane->AddTab(textfield_example.GetExampleTitle(), tabbed_pane->AddTab(textfield_example.GetExampleTitle(),
textfield_example.GetExampleView()); textfield_example.GetExampleView());
......
// 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
// 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_
...@@ -388,6 +388,8 @@ ...@@ -388,6 +388,8 @@
'window/native_window_delegate.h', 'window/native_window_delegate.h',
'window/native_window_gtk.cc', 'window/native_window_gtk.cc',
'window/native_window_gtk.h', 'window/native_window_gtk.h',
'window/native_window_views.cc',
'window/native_window_views.h',
'window/native_window_win.cc', 'window/native_window_win.cc',
'window/native_window_win.h', 'window/native_window_win.h',
'window/non_client_view.cc', 'window/non_client_view.cc',
...@@ -579,6 +581,8 @@ ...@@ -579,6 +581,8 @@
'examples/native_theme_checkbox_example.h', 'examples/native_theme_checkbox_example.h',
'examples/native_widget_views_example.cc', 'examples/native_widget_views_example.cc',
'examples/native_widget_views_example.h', '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.cc',
'examples/radio_button_example.h', 'examples/radio_button_example.h',
'examples/scroll_view_example.cc', 'examples/scroll_view_example.cc',
......
...@@ -27,6 +27,10 @@ View* NativeWidgetViews::GetView() { ...@@ -27,6 +27,10 @@ View* NativeWidgetViews::GetView() {
return view_; return view_;
} }
const View* NativeWidgetViews::GetView() const {
return view_;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews, NativeWidget implementation: // NativeWidgetViews, NativeWidget implementation:
......
...@@ -26,6 +26,7 @@ class NativeWidgetViews : public NativeWidget { ...@@ -26,6 +26,7 @@ class NativeWidgetViews : public NativeWidget {
// TODO(beng): remove. // TODO(beng): remove.
View* GetView(); View* GetView();
const View* GetView() const;
internal::NativeWidgetDelegate* delegate() { return delegate_; } internal::NativeWidgetDelegate* delegate() { return delegate_; }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "views/events/event.h" #include "views/events/event.h"
#include "views/screen.h" #include "views/screen.h"
#include "views/window/custom_frame_view.h"
#include "views/window/hit_test.h" #include "views/window/hit_test.h"
#include "views/window/native_window_delegate.h" #include "views/window/native_window_delegate.h"
#include "views/window/non_client_view.h" #include "views/window/non_client_view.h"
...@@ -364,7 +363,7 @@ void NativeWindowGtk::SetUseDragFrame(bool use_drag_frame) { ...@@ -364,7 +363,7 @@ void NativeWindowGtk::SetUseDragFrame(bool use_drag_frame) {
} }
NonClientFrameView* NativeWindowGtk::CreateFrameViewForWindow() { NonClientFrameView* NativeWindowGtk::CreateFrameViewForWindow() {
return new CustomFrameView(delegate_->AsWindow()); return NULL;
} }
void NativeWindowGtk::SetAlwaysOnTop(bool always_on_top) { void NativeWindowGtk::SetAlwaysOnTop(bool always_on_top) {
......
// 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
// 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_
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
#include "views/accessibility/native_view_accessibility_win.h" #include "views/accessibility/native_view_accessibility_win.h"
#include "views/window/client_view.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_window_delegate.h"
#include "views/window/native_frame_view.h" #include "views/window/native_frame_view.h"
#include "views/window/non_client_view.h" #include "views/window/non_client_view.h"
...@@ -1308,9 +1307,8 @@ void NativeWindowWin::SetUseDragFrame(bool use_drag_frame) { ...@@ -1308,9 +1307,8 @@ void NativeWindowWin::SetUseDragFrame(bool use_drag_frame) {
} }
NonClientFrameView* NativeWindowWin::CreateFrameViewForWindow() { NonClientFrameView* NativeWindowWin::CreateFrameViewForWindow() {
if (GetWindow()->ShouldUseNativeFrame()) return GetWindow()->ShouldUseNativeFrame() ?
return new NativeFrameView(GetWindow()); new NativeFrameView(GetWindow()) : NULL;
return new CustomFrameView(GetWindow());
} }
void NativeWindowWin::UpdateFrameAfterFrameChange() { void NativeWindowWin::UpdateFrameAfterFrameChange() {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
#include "views/widget/widget.h" #include "views/widget/widget.h"
#include "views/widget/native_widget.h" #include "views/widget/native_widget.h"
#include "views/window/custom_frame_view.h"
#include "views/window/native_window.h" #include "views/window/native_window.h"
#include "views/window/window_delegate.h" #include "views/window/window_delegate.h"
...@@ -229,7 +230,8 @@ void Window::SetIsAlwaysOnTop(bool always_on_top) { ...@@ -229,7 +230,8 @@ void Window::SetIsAlwaysOnTop(bool always_on_top) {
} }
NonClientFrameView* Window::CreateFrameViewForWindow() { NonClientFrameView* Window::CreateFrameViewForWindow() {
return native_window_->CreateFrameViewForWindow(); NonClientFrameView* frame_view = native_window_->CreateFrameViewForWindow();
return frame_view ? frame_view : new CustomFrameView(this);
} }
void Window::UpdateFrameAfterFrameChange() { void Window::UpdateFrameAfterFrameChange() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment