diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 03:15:34 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 03:15:34 +0000 |
commit | 6f637730a38de10a1173f05e48271483d27b648d (patch) | |
tree | 44bacffdd54e6b8d28215b4a7ccd9a06bbeb88ef /ui/aura/root_window_host_mac.mm | |
parent | e48c61d39a63a10675af85eb9417ed453eea6a6a (diff) | |
download | chromium_src-6f637730a38de10a1173f05e48271483d27b648d.zip chromium_src-6f637730a38de10a1173f05e48271483d27b648d.tar.gz chromium_src-6f637730a38de10a1173f05e48271483d27b648d.tar.bz2 |
Aura Shell needs to exist on Mac
Adds first cut at "Aura Shell.app" on Mac. The 'ash_shell' is extended
to generate a Cocoa application. This application brings up a single
window containing the Aura desktop. The main view of this window provides
an accelerated surface to Aura in which it can composite and draw its
results.
What works:
- The application launches and renders the Aura desktop and background
- Mouse movement, clicking, double-clicking, and interactions with
Aura windows and widgets
- Text buttons render with Skia text (needs improvement)
- Non-modal transient window button
- Window-modal window button
- System-modal window button
- Example Widgets button (checkboxes, radios, buttons)
- Lock Screen button
- Create Non-Resizable window button
- Create Pointy Bubble button
- Create Widow button
- Switcher and Taskbar
What doesn't work:
- Open Views Examples Window button
- Views menus
- Views scrollbars
- Views accelerators
- Views tooltips
- Drag and drop
- Anything involving MessageLoop dispatcher logic
- Mouse movement doesn't pass through to Aura when mouse button is up
Note: Required .gyp flags are:
'use_aura': 1,
'use_webkit_compositor': 1,
BUG=109946
TEST=Manual tests.
R=sky@chromium.org, thakis@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9232028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118222 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura/root_window_host_mac.mm')
-rw-r--r-- | ui/aura/root_window_host_mac.mm | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/ui/aura/root_window_host_mac.mm b/ui/aura/root_window_host_mac.mm new file mode 100644 index 0000000..0660a8d --- /dev/null +++ b/ui/aura/root_window_host_mac.mm @@ -0,0 +1,189 @@ +// Copyright (c) 2012 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 "ui/aura/root_window_host_mac.h" + +#import <Cocoa/Cocoa.h> + +#include "base/compiler_specific.h" +#include "base/memory/scoped_nsobject.h" +#include "ui/aura/event.h" +#include "ui/aura/root_window.h" +#include "ui/aura/root_window_host.h" +#include "ui/aura/root_window_mac.h" +#include "ui/aura/root_window_view_mac.h" +#include "ui/gfx/point.h" + +namespace aura { + +// The Mac-specific implementation of the RootWindowHost interface. This class +// acts at an intermediary between the Aura shell and an NSWindow. The +// association between the Aura compositor and the native window's view is +// established with this class as is the association between the native window's +// event dispatch and the Aura event processing. +class RootWindowHostMac : public RootWindowHost, + public RootWindowHostMacDelegate { + public: + explicit RootWindowHostMac(const gfx::Rect& bounds); + virtual ~RootWindowHostMac(); + + // RootWindowHost: + virtual void SetRootWindow(RootWindow* root_window) OVERRIDE; + virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; + virtual void Show() OVERRIDE; + virtual void ToggleFullScreen() OVERRIDE; + virtual gfx::Size GetSize() const OVERRIDE; + virtual void SetSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; + virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; + virtual void ShowCursor(bool show) OVERRIDE; + virtual gfx::Point QueryMouseLocation() OVERRIDE; + virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE; + + // RootWindowHostMacDelegate: + virtual void SendEvent(const base::NativeEvent& native_event) OVERRIDE; + + // Set the initial location of the root window. The origin of |bounds| is + // top-left. This gets converted to bottom-left to match Mac coordinates on + // the main screen. + void SetLocation(const gfx::Rect& bounds); + + private: + // Weak reference. + RootWindow* root_window_; + + // The bounds of the Aura desktop. Relative to Aura's coordinate system. + // This is currently used only for size information, not location. + gfx::Rect bounds_; + + // An NSWindowController for the root window. Controls the actual Cocoa + // window on Mac. + scoped_nsobject<NSWindowController> controller_; + + DISALLOW_COPY_AND_ASSIGN(RootWindowHostMac); +}; + +RootWindowHostMacDelegate::RootWindowHostMacDelegate() { +} + +RootWindowHostMacDelegate::~RootWindowHostMacDelegate() { +} + +RootWindowHostMac::RootWindowHostMac(const gfx::Rect& bounds) + : root_window_(NULL), bounds_(bounds) { + controller_.reset([[NSWindowController alloc] + initWithWindowNibName:@"RootWindow"]); + SetSize(bounds.size()); + SetLocation(bounds); +} + +RootWindowHostMac::~RootWindowHostMac() { +} + +// static +RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { + return new RootWindowHostMac(bounds); +} + +// static +gfx::Size RootWindowHost::GetNativeScreenSize() { + NSRect screen = [[NSScreen mainScreen] visibleFrame]; + return gfx::Size(NSSizeToCGSize(screen.size)); +} + +void RootWindowHostMac::SetRootWindow(RootWindow* root_window) { + root_window_ = root_window; + + RootWindowView* view = [[controller_ window] contentView]; + DCHECK([view respondsToSelector:@selector(setCompositor:)]); + [view setCompositor:root_window->compositor()]; + + RootWindowMac* window = static_cast<RootWindowMac*>([controller_ window]); + DCHECK([window respondsToSelector:@selector(setHostDelegate:)]); + [window setHostDelegate:this]; +} + +gfx::AcceleratedWidget RootWindowHostMac::GetAcceleratedWidget() { + return [[controller_ window] contentView]; +} + +void RootWindowHostMac::Show() { + [controller_ showWindow:controller_]; +} + +void RootWindowHostMac::ToggleFullScreen() { +} + +gfx::Size RootWindowHostMac::GetSize() const { + NSSize size = [[[controller_ window] contentView] bounds].size; + return gfx::Size(NSSizeToCGSize(size)); +} + +void RootWindowHostMac::SetSize(const gfx::Size& size) { + NSSize nssize = NSSizeFromCGSize(size.ToCGSize()); + [[controller_ window] setContentSize:nssize]; + [[controller_ window] setContentMaxSize:nssize]; + [[controller_ window] setContentMinSize:nssize]; +} + +gfx::Point RootWindowHostMac::GetLocationOnNativeScreen() const { + return gfx::Point(); +} + +void RootWindowHostMac::SetCursor(gfx::NativeCursor cursor) { +} + +void RootWindowHostMac::ShowCursor(bool show) { +} + +gfx::Point RootWindowHostMac::QueryMouseLocation() { + return gfx::Point(); +} + +void RootWindowHostMac::MoveCursorTo(const gfx::Point& location) { +} + +void RootWindowHostMac::SendEvent(const base::NativeEvent& native_event) { + ui::EventType type = ui::EventTypeFromNative(native_event); + switch (type) { + case ui::ET_MOUSE_PRESSED: + case ui::ET_MOUSE_DRAGGED: + case ui::ET_MOUSE_RELEASED: + case ui::ET_MOUSE_MOVED: + case ui::ET_MOUSE_ENTERED: + case ui::ET_MOUSE_EXITED: { + MouseEvent mouse_event(native_event); + root_window_->DispatchMouseEvent(&mouse_event); + break; + } + case ui::ET_KEY_PRESSED: + case ui::ET_KEY_RELEASED: { + KeyEvent key_event(native_event, false); + root_window_->DispatchKeyEvent(&key_event); + break; + } + case ui::ET_MOUSEWHEEL: + case ui::ET_TOUCH_RELEASED: + case ui::ET_TOUCH_PRESSED: + case ui::ET_TOUCH_MOVED: + case ui::ET_TOUCH_STATIONARY: + case ui::ET_TOUCH_CANCELLED: + case ui::ET_DROP_TARGET_EVENT: + case ui::ET_FOCUS_CHANGE: + case ui::ET_SCROLL: + case ui::ET_UNKNOWN: + default: + break; + } +} + +void RootWindowHostMac::SetLocation(const gfx::Rect& bounds) { + NSRect screen = [[NSScreen mainScreen] visibleFrame]; + NSPoint origin = NSMakePoint(screen.origin.x + bounds.x(), + screen.origin.y + screen.size.height - + bounds.y() - bounds.height()); + [[controller_ window] setFrameOrigin:origin]; +} + +} // namespace aura |