Skip to content

Commit

Permalink
Adds a NonClientFrameView for generic toplevel windows.Also adds a fe…
Browse files Browse the repository at this point in the history
…eble (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
  • Loading branch information
ben@chromium.org committed Sep 22, 2011
1 parent c7f2ef7 commit 70ccf70
Show file tree
Hide file tree
Showing 19 changed files with 583 additions and 6 deletions.
1 change: 1 addition & 0 deletions ui/aura/aura.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'AURA_IMPLEMENTATION',
],
'sources': [
'cursor.h',
'desktop_host.h',
'desktop_host_linux.cc',
'desktop_host_win.cc',
Expand Down
23 changes: 23 additions & 0 deletions ui/aura/cursor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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_
5 changes: 1 addition & 4 deletions ui/aura/demo/demo_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
4 changes: 4 additions & 0 deletions ui/aura/desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 5 additions & 1 deletion ui/aura/desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions ui/aura/desktop_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions ui/aura/desktop_host_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions ui/aura/desktop_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions ui/aura/desktop_host_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion ui/aura/toplevel_window_event_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions ui/aura/toplevel_window_event_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
2 changes: 2 additions & 0 deletions ui/aura_shell/aura_shell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
'shell_factory.h',
'status_area_view.cc',
'status_area_view.h',
'toplevel_frame_view.cc',
'toplevel_frame_view.h',
],
},
{
Expand Down
9 changes: 9 additions & 0 deletions ui/aura_shell/examples/window_type_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_) {
Expand Down
2 changes: 2 additions & 0 deletions ui/aura_shell/examples/window_type_launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 70ccf70

Please sign in to comment.