Commit 70ccf706 authored by ben@chromium.org's avatar ben@chromium.org

Adds a NonClientFrameView for generic toplevel windows.Also adds a feeble (but...

Adds a NonClientFrameView for generic toplevel windows.Also adds a feeble (but better than what there was) attempt at sometimes updating the cursor. Will have to be replaced by a better system, but it's a start.http://crbug.com/97247TEST=none
Review URL: http://codereview.chromium.org/7977012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102312 0039d316-1c4b-4281-b951-d872f2087c98
parent c7f2ef7c
......@@ -23,6 +23,7 @@
'AURA_IMPLEMENTATION',
],
'sources': [
'cursor.h',
'desktop_host.h',
'desktop_host_linux.cc',
'desktop_host_win.cc',
......
// 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 UI_AURA_CURSOR_H_
#define UI_AURA_CURSOR_H_
#pragma once
#include "ui/aura/aura_export.h"
namespace aura {
enum AURA_EXPORT CursorType {
CURSOR_POINTER,
CURSOR_LINK,
CURSOR_WAIT,
CURSOR_SIZE_HORIZONTAL,
CURSOR_SIZE_VERTICAL
};
} // namespace aura
#endif // UI_AURA_CURSOR_H_
......@@ -37,19 +37,16 @@ class DemoWindowDelegate : public aura::WindowDelegate {
virtual bool OnKeyEvent(aura::KeyEvent* event) OVERRIDE {
return false;
}
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
return HTCAPTION;
}
virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE {
return true;
}
virtual void OnCaptureLost() OVERRIDE {}
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode);
}
virtual void OnWindowDestroying() OVERRIDE {}
virtual void OnWindowDestroyed() OVERRIDE {}
......
......@@ -57,6 +57,10 @@ void Desktop::SetSize(const gfx::Size& size) {
host_->SetSize(size);
}
void Desktop::SetCursor(CursorType cursor_type) {
host_->SetCursor(cursor_type);
}
void Desktop::Run() {
Show();
MessageLoopForUI::current()->Run(host_.get());
......
......@@ -9,8 +9,9 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/task.h"
#include "ui/aura/root_window.h"
#include "ui/aura/aura_export.h"
#include "ui/aura/cursor.h"
#include "ui/aura/root_window.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/native_widget_types.h"
......@@ -38,6 +39,9 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate {
// Sets the size of the desktop.
void SetSize(const gfx::Size& size);
// Shows the specified cursor.
void SetCursor(CursorType cursor_type);
// Shows the desktop host and runs an event loop for it.
void Run();
......
......@@ -7,6 +7,7 @@
#pragma once
#include "base/message_loop.h"
#include "ui/aura/cursor.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
......@@ -40,6 +41,9 @@ class DesktopHost : public MessageLoop::Dispatcher {
// Gets/Sets the size of the DesktopHost.
virtual gfx::Size GetSize() = 0;
virtual void SetSize(const gfx::Size& size) = 0;
// Sets the currently displayed cursor.
virtual void SetCursor(CursorType cursor_type) = 0;
};
} // namespace aura
......
......@@ -30,6 +30,7 @@ class DesktopHostLinux : public DesktopHost {
virtual void Show() OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
virtual void SetCursor(CursorType cursor_type) OVERRIDE;
Desktop* desktop_;
......@@ -113,6 +114,10 @@ void DesktopHostLinux::SetSize(const gfx::Size& size) {
XResizeWindow(xdisplay_, xwindow_, size.width(), size.height());
}
void DesktopHostLinux::SetCursor(CursorType cursor_type) {
NOTIMPLEMENTED();
}
} // namespace
// static
......
......@@ -58,6 +58,28 @@ void DesktopHostWin::SetSize(const gfx::Size& size) {
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION);
}
void DesktopHostWin::SetCursor(CursorType cursor_type) {
switch (cursor_type) {
case CURSOR_POINTER:
::SetCursor(LoadCursor(NULL, IDC_ARROW));
break;
case CURSOR_LINK:
::SetCursor(LoadCursor(NULL, IDC_HAND));
break;
case CURSOR_WAIT:
::SetCursor(LoadCursor(NULL, IDC_WAIT));
break;
case CURSOR_SIZE_HORIZONTAL:
::SetCursor(LoadCursor(NULL, IDC_SIZEWE));
break;
case CURSOR_SIZE_VERTICAL:
::SetCursor(LoadCursor(NULL, IDC_SIZENS));
break;
default:
break;
}
}
void DesktopHostWin::OnClose() {
// TODO: this obviously shouldn't be here.
MessageLoopForUI::current()->Quit();
......
......@@ -26,6 +26,7 @@ class DesktopHostWin : public DesktopHost, public ui::WindowImpl {
virtual void Show() OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
virtual void SetCursor(CursorType cursor_type) OVERRIDE;
private:
BEGIN_MSG_MAP_EX(DesktopHostWin)
......
......@@ -4,6 +4,8 @@
#include "ui/aura/toplevel_window_event_filter.h"
#include "ui/aura/cursor.h"
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
......@@ -25,9 +27,12 @@ ToplevelWindowEventFilter::~ToplevelWindowEventFilter() {
bool ToplevelWindowEventFilter::OnMouseEvent(Window* target,
MouseEvent* event) {
switch (event->type()) {
case ui::ET_MOUSE_PRESSED:
case ui::ET_MOUSE_MOVED:
window_component_ =
target->delegate()->GetNonClientComponent(event->location());
UpdateCursorForWindowComponent();
break;
case ui::ET_MOUSE_PRESSED:
MoveWindowToFront(target);
mouse_down_offset_ = event->location();
window_location_ = target->bounds().origin();
......@@ -64,4 +69,19 @@ void ToplevelWindowEventFilter::MoveWindowToFront(Window* target) {
}
}
void ToplevelWindowEventFilter::UpdateCursorForWindowComponent() {
switch (window_component_) {
case HTLEFT:
case HTRIGHT:
Desktop::GetInstance()->SetCursor(CURSOR_SIZE_HORIZONTAL);
break;
case HTBOTTOM:
Desktop::GetInstance()->SetCursor(CURSOR_SIZE_VERTICAL);
break;
default:
Desktop::GetInstance()->SetCursor(CURSOR_POINTER);
break;
}
}
} // namespace aura
......@@ -28,6 +28,8 @@ class ToplevelWindowEventFilter : public EventFilter {
// respective z-orders.
void MoveWindowToFront(Window* target);
void UpdateCursorForWindowComponent();
gfx::Point mouse_down_offset_;
gfx::Point window_location_;
int window_component_;
......
......@@ -42,6 +42,8 @@
'shell_factory.h',
'status_area_view.cc',
'status_area_view.h',
'toplevel_frame_view.cc',
'toplevel_frame_view.h',
],
},
{
......
......@@ -8,6 +8,7 @@
#include "ui/aura/window.h"
#include "ui/aura_shell/examples/example_factory.h"
#include "ui/aura_shell/examples/toplevel_window.h"
#include "ui/aura_shell/toplevel_frame_view.h"
#include "ui/gfx/canvas.h"
#include "views/controls/button/text_button.h"
#include "views/controls/menu/menu_item_view.h"
......@@ -71,10 +72,18 @@ views::View* WindowTypeLauncher::GetContentsView() {
return this;
}
bool WindowTypeLauncher::CanResize() const {
return true;
}
std::wstring WindowTypeLauncher::GetWindowTitle() const {
return L"Examples: Window Builder";
}
views::NonClientFrameView* WindowTypeLauncher::CreateNonClientFrameView() {
return new aura_shell::internal::ToplevelFrameView;
}
void WindowTypeLauncher::ButtonPressed(views::Button* sender,
const views::Event& event) {
if (sender == create_button_) {
......
......@@ -42,7 +42,9 @@ class WindowTypeLauncher : public views::WidgetDelegateView,
// Overridden from views::WidgetDelegate:
virtual views::View* GetContentsView() OVERRIDE;
virtual bool CanResize() const OVERRIDE;
virtual std::wstring GetWindowTitle() const OVERRIDE;
virtual views::NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
// Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
......
This diff is collapsed.
// 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 UI_AURA_SHELL_TOPLEVEL_FRAME_VIEW_H_
#define UI_AURA_SHELL_TOPLEVEL_FRAME_VIEW_H_
#pragma once
#include "ui/aura_shell/aura_shell_export.h"
#include "ui/base/animation/animation_delegate.h"
#include "views/controls/button/button.h"
#include "views/window/non_client_view.h"
namespace ui {
class SlideAnimation;
}
namespace aura_shell {
namespace internal {
class SizingBorder;
// A NonClientFrameView implementation for generic top-level windows in Aura.
// TODO(beng): Find a way to automatically this for all top-level windows in
// Aura. Right now windows have to override CreateNonClientFrameView
// on WidgetDelegate to specify this.
class AURA_SHELL_EXPORT ToplevelFrameView : public views::NonClientFrameView,
public views::ButtonListener {
public:
ToplevelFrameView();
virtual ~ToplevelFrameView();
private:
// Returns the height of the side/bottom non-client edges.
int NonClientBorderThickness() const;
// Returns the height of the top non-client edge - the caption.
int NonClientTopBorderHeight() const;
// Implementation of NonClientHitTest().
int NonClientHitTestImpl(const gfx::Point& point);
// Shows the specified |sizing_border|, hiding all others.
// If |sizing_border| is NULL, all other sizing borders are hidden.
void ShowSizingBorder(SizingBorder* sizing_border);
// Returns true if the specified point (in FrameView coordinates) hit-tests
// against the specified child.
bool PointIsInChildView(views::View* child, const gfx::Point& point) const;
// Returns the bounds of the specified sizing border for its visible and
// hidden states.
gfx::Rect GetHiddenBoundsForSizingBorder(int frame_component) const;
gfx::Rect GetVisibleBoundsForSizingBorder(int frame_component) const;
// Overridden from views::NonClientFrameView:
virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
virtual gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const OVERRIDE;
virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
virtual void GetWindowMask(const gfx::Size& size,
gfx::Path* window_mask) OVERRIDE;
virtual void EnableClose(bool enable) OVERRIDE;
virtual void ResetWindowControls() OVERRIDE;
virtual void UpdateWindowIcon() OVERRIDE;
// Overridden from views::View:
virtual void Layout() OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
virtual views::View* GetEventHandlerForPoint(
const gfx::Point& point) OVERRIDE;
// Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const views::Event& event) OVERRIDE;
gfx::Rect client_view_bounds_;
views::Button* close_button_;
views::Button* zoom_button_;
int current_hittest_code_;
SizingBorder* left_edge_;
SizingBorder* right_edge_;
SizingBorder* bottom_edge_;
DISALLOW_COPY_AND_ASSIGN(ToplevelFrameView);
};
} // namespace internal
} // namespace aura_shell
#endif // #ifndef UI_AURA_SHELL_TOPLEVEL_FRAME_VIEW_H_
......@@ -125,6 +125,8 @@
<include name="IDR_AURA_LAUNCHER_ICON_APPLIST" file="aura/applist.png" type="BINDATA" />
<include name="IDR_AURA_STATUS_MOCK" file="aura/statusbar.png" type="BINDATA" />
<include name="IDR_AURA_WALLPAPER" file="aura/damask.png" type="BINDATA" />
<include name="IDR_AURA_WINDOW_CLOSE_ICON" file="aura/slab_close.png" type="BINDATA" />
<include name="IDR_AURA_WINDOW_ZOOM_ICON" file="aura/slab_zoom.png" type="BINDATA" />
</if>
</includes>
</release>
......
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