Home | History | Annotate | Download | only in widget
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ui/views/widget/native_widget_mac.h"
      6 
      7 #import <Cocoa/Cocoa.h>
      8 
      9 #include "base/mac/scoped_nsobject.h"
     10 #include "ui/gfx/font_list.h"
     11 #include "ui/native_theme/native_theme.h"
     12 #import "ui/views/cocoa/bridged_content_view.h"
     13 #import "ui/views/cocoa/bridged_native_widget.h"
     14 
     15 namespace views {
     16 
     17 ////////////////////////////////////////////////////////////////////////////////
     18 // NativeWidgetMac, public:
     19 
     20 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate)
     21     : delegate_(delegate), bridge_(new BridgedNativeWidget) {
     22 }
     23 
     24 NativeWidgetMac::~NativeWidgetMac() {
     25 }
     26 
     27 ////////////////////////////////////////////////////////////////////////////////
     28 // NativeWidgetMac, internal::NativeWidgetPrivate implementation:
     29 
     30 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) {
     31   // TODO(tapted): Convert position into Cocoa's flipped coordinate space.
     32   NSRect content_rect =
     33       NSMakeRect(0, 0, params.bounds.width(), params.bounds.height());
     34   // TODO(tapted): Determine a good initial style mask from |params|.
     35   NSInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
     36                          NSMiniaturizableWindowMask | NSResizableWindowMask;
     37   base::scoped_nsobject<NSWindow> window(
     38       [[NSWindow alloc] initWithContentRect:content_rect
     39                                   styleMask:style_mask
     40                                     backing:NSBackingStoreBuffered
     41                                       defer:NO]);
     42   bridge_->Init(window);
     43 }
     44 
     45 NonClientFrameView* NativeWidgetMac::CreateNonClientFrameView() {
     46   return NULL;
     47 }
     48 
     49 bool NativeWidgetMac::ShouldUseNativeFrame() const {
     50   return false;
     51 }
     52 
     53 bool NativeWidgetMac::ShouldWindowContentsBeTransparent() const {
     54   NOTIMPLEMENTED();
     55   return false;
     56 }
     57 
     58 void NativeWidgetMac::FrameTypeChanged() {
     59   NOTIMPLEMENTED();
     60 }
     61 
     62 Widget* NativeWidgetMac::GetWidget() {
     63   return delegate_->AsWidget();
     64 }
     65 
     66 const Widget* NativeWidgetMac::GetWidget() const {
     67   return delegate_->AsWidget();
     68 }
     69 
     70 gfx::NativeView NativeWidgetMac::GetNativeView() const {
     71   return bridge_->ns_view();
     72 }
     73 
     74 gfx::NativeWindow NativeWidgetMac::GetNativeWindow() const {
     75   return bridge_->ns_window();
     76 }
     77 
     78 Widget* NativeWidgetMac::GetTopLevelWidget() {
     79   NOTIMPLEMENTED();
     80   return GetWidget();
     81 }
     82 
     83 const ui::Compositor* NativeWidgetMac::GetCompositor() const {
     84   NOTIMPLEMENTED();
     85   return NULL;
     86 }
     87 
     88 ui::Compositor* NativeWidgetMac::GetCompositor() {
     89   NOTIMPLEMENTED();
     90   return NULL;
     91 }
     92 
     93 ui::Layer* NativeWidgetMac::GetLayer() {
     94   NOTIMPLEMENTED();
     95   return NULL;
     96 }
     97 
     98 void NativeWidgetMac::ReorderNativeViews() {
     99   bridge_->SetRootView(GetWidget()->GetRootView());
    100 }
    101 
    102 void NativeWidgetMac::ViewRemoved(View* view) {
    103   NOTIMPLEMENTED();
    104 }
    105 
    106 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) {
    107   NOTIMPLEMENTED();
    108 }
    109 
    110 void* NativeWidgetMac::GetNativeWindowProperty(const char* name) const {
    111   NOTIMPLEMENTED();
    112   return NULL;
    113 }
    114 
    115 TooltipManager* NativeWidgetMac::GetTooltipManager() const {
    116   NOTIMPLEMENTED();
    117   return NULL;
    118 }
    119 
    120 void NativeWidgetMac::SetCapture() {
    121   NOTIMPLEMENTED();
    122 }
    123 
    124 void NativeWidgetMac::ReleaseCapture() {
    125   NOTIMPLEMENTED();
    126 }
    127 
    128 bool NativeWidgetMac::HasCapture() const {
    129   NOTIMPLEMENTED();
    130   return false;
    131 }
    132 
    133 InputMethod* NativeWidgetMac::CreateInputMethod() {
    134   return bridge_->CreateInputMethod();
    135 }
    136 
    137 internal::InputMethodDelegate* NativeWidgetMac::GetInputMethodDelegate() {
    138   return bridge_.get();
    139 }
    140 
    141 ui::InputMethod* NativeWidgetMac::GetHostInputMethod() {
    142   return bridge_->GetHostInputMethod();
    143 }
    144 
    145 void NativeWidgetMac::CenterWindow(const gfx::Size& size) {
    146   NOTIMPLEMENTED();
    147 }
    148 
    149 void NativeWidgetMac::GetWindowPlacement(gfx::Rect* bounds,
    150                                          ui::WindowShowState* maximized) const {
    151   NOTIMPLEMENTED();
    152 }
    153 
    154 bool NativeWidgetMac::SetWindowTitle(const base::string16& title) {
    155   NOTIMPLEMENTED();
    156   return false;
    157 }
    158 
    159 void NativeWidgetMac::SetWindowIcons(const gfx::ImageSkia& window_icon,
    160                                      const gfx::ImageSkia& app_icon) {
    161   NOTIMPLEMENTED();
    162 }
    163 
    164 void NativeWidgetMac::InitModalType(ui::ModalType modal_type) {
    165   NOTIMPLEMENTED();
    166 }
    167 
    168 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const {
    169   NOTIMPLEMENTED();
    170   return gfx::Rect();
    171 }
    172 
    173 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const {
    174   NOTIMPLEMENTED();
    175   return gfx::Rect();
    176 }
    177 
    178 gfx::Rect NativeWidgetMac::GetRestoredBounds() const {
    179   NOTIMPLEMENTED();
    180   return gfx::Rect();
    181 }
    182 
    183 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) {
    184   NOTIMPLEMENTED();
    185 }
    186 
    187 void NativeWidgetMac::SetSize(const gfx::Size& size) {
    188   [bridge_->ns_window() setContentSize:NSMakeSize(size.width(), size.height())];
    189 }
    190 
    191 void NativeWidgetMac::StackAbove(gfx::NativeView native_view) {
    192   NOTIMPLEMENTED();
    193 }
    194 
    195 void NativeWidgetMac::StackAtTop() {
    196   NOTIMPLEMENTED();
    197 }
    198 
    199 void NativeWidgetMac::StackBelow(gfx::NativeView native_view) {
    200   NOTIMPLEMENTED();
    201 }
    202 
    203 void NativeWidgetMac::SetShape(gfx::NativeRegion shape) {
    204   NOTIMPLEMENTED();
    205 }
    206 
    207 void NativeWidgetMac::Close() {
    208   NOTIMPLEMENTED();
    209 }
    210 
    211 void NativeWidgetMac::CloseNow() {
    212   NOTIMPLEMENTED();
    213 }
    214 
    215 void NativeWidgetMac::Show() {
    216   NOTIMPLEMENTED();
    217 }
    218 
    219 void NativeWidgetMac::Hide() {
    220   NOTIMPLEMENTED();
    221 }
    222 
    223 void NativeWidgetMac::ShowMaximizedWithBounds(
    224     const gfx::Rect& restored_bounds) {
    225   NOTIMPLEMENTED();
    226 }
    227 
    228 void NativeWidgetMac::ShowWithWindowState(ui::WindowShowState state) {
    229   NOTIMPLEMENTED();
    230 }
    231 
    232 bool NativeWidgetMac::IsVisible() const {
    233   NOTIMPLEMENTED();
    234   return true;
    235 }
    236 
    237 void NativeWidgetMac::Activate() {
    238   NOTIMPLEMENTED();
    239 }
    240 
    241 void NativeWidgetMac::Deactivate() {
    242   NOTIMPLEMENTED();
    243 }
    244 
    245 bool NativeWidgetMac::IsActive() const {
    246   NOTIMPLEMENTED();
    247   return true;
    248 }
    249 
    250 void NativeWidgetMac::SetAlwaysOnTop(bool always_on_top) {
    251   NOTIMPLEMENTED();
    252 }
    253 
    254 bool NativeWidgetMac::IsAlwaysOnTop() const {
    255   NOTIMPLEMENTED();
    256   return false;
    257 }
    258 
    259 void NativeWidgetMac::SetVisibleOnAllWorkspaces(bool always_visible) {
    260   NOTIMPLEMENTED();
    261 }
    262 
    263 void NativeWidgetMac::Maximize() {
    264   NOTIMPLEMENTED();
    265 }
    266 
    267 void NativeWidgetMac::Minimize() {
    268   NOTIMPLEMENTED();
    269 }
    270 
    271 bool NativeWidgetMac::IsMaximized() const {
    272   NOTIMPLEMENTED();
    273   return false;
    274 }
    275 
    276 bool NativeWidgetMac::IsMinimized() const {
    277   NOTIMPLEMENTED();
    278   return false;
    279 }
    280 
    281 void NativeWidgetMac::Restore() {
    282   NOTIMPLEMENTED();
    283 }
    284 
    285 void NativeWidgetMac::SetFullscreen(bool fullscreen) {
    286   NOTIMPLEMENTED();
    287 }
    288 
    289 bool NativeWidgetMac::IsFullscreen() const {
    290   NOTIMPLEMENTED();
    291   return false;
    292 }
    293 
    294 void NativeWidgetMac::SetOpacity(unsigned char opacity) {
    295   NOTIMPLEMENTED();
    296 }
    297 
    298 void NativeWidgetMac::SetUseDragFrame(bool use_drag_frame) {
    299   NOTIMPLEMENTED();
    300 }
    301 
    302 void NativeWidgetMac::FlashFrame(bool flash_frame) {
    303   NOTIMPLEMENTED();
    304 }
    305 
    306 void NativeWidgetMac::RunShellDrag(View* view,
    307                                    const ui::OSExchangeData& data,
    308                                    const gfx::Point& location,
    309                                    int operation,
    310                                    ui::DragDropTypes::DragEventSource source) {
    311   NOTIMPLEMENTED();
    312 }
    313 
    314 void NativeWidgetMac::SchedulePaintInRect(const gfx::Rect& rect) {
    315   // TODO(tapted): This should use setNeedsDisplayInRect:, once the coordinate
    316   // system of |rect| has been converted.
    317   [bridge_->ns_view() setNeedsDisplay:YES];
    318 }
    319 
    320 void NativeWidgetMac::SetCursor(gfx::NativeCursor cursor) {
    321   NOTIMPLEMENTED();
    322 }
    323 
    324 bool NativeWidgetMac::IsMouseEventsEnabled() const {
    325   NOTIMPLEMENTED();
    326   return true;
    327 }
    328 
    329 void NativeWidgetMac::ClearNativeFocus() {
    330   NOTIMPLEMENTED();
    331 }
    332 
    333 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const {
    334   NOTIMPLEMENTED();
    335   return gfx::Rect();
    336 }
    337 
    338 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop(
    339     const gfx::Vector2d& drag_offset,
    340     Widget::MoveLoopSource source,
    341     Widget::MoveLoopEscapeBehavior escape_behavior) {
    342   NOTIMPLEMENTED();
    343   return Widget::MOVE_LOOP_CANCELED;
    344 }
    345 
    346 void NativeWidgetMac::EndMoveLoop() {
    347   NOTIMPLEMENTED();
    348 }
    349 
    350 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) {
    351   NOTIMPLEMENTED();
    352 }
    353 
    354 ui::NativeTheme* NativeWidgetMac::GetNativeTheme() const {
    355   return ui::NativeTheme::instance();
    356 }
    357 
    358 void NativeWidgetMac::OnRootViewLayout() const {
    359   NOTIMPLEMENTED();
    360 }
    361 
    362 bool NativeWidgetMac::IsTranslucentWindowOpacitySupported() const {
    363   return false;
    364 }
    365 
    366 void NativeWidgetMac::RepostNativeEvent(gfx::NativeEvent native_event) {
    367   NOTIMPLEMENTED();
    368 }
    369 
    370 ////////////////////////////////////////////////////////////////////////////////
    371 // Widget, public:
    372 
    373 bool Widget::ConvertRect(const Widget* source,
    374                          const Widget* target,
    375                          gfx::Rect* rect) {
    376   return false;
    377 }
    378 
    379 namespace internal {
    380 
    381 ////////////////////////////////////////////////////////////////////////////////
    382 // internal::NativeWidgetPrivate, public:
    383 
    384 // static
    385 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget(
    386     internal::NativeWidgetDelegate* delegate) {
    387   return new NativeWidgetMac(delegate);
    388 }
    389 
    390 // static
    391 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView(
    392     gfx::NativeView native_view) {
    393   NOTIMPLEMENTED();
    394   return NULL;
    395 }
    396 
    397 // static
    398 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
    399     gfx::NativeWindow native_window) {
    400   NOTIMPLEMENTED();
    401   return NULL;
    402 }
    403 
    404 // static
    405 NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget(
    406     gfx::NativeView native_view) {
    407   NOTIMPLEMENTED();
    408   return NULL;
    409 }
    410 
    411 // static
    412 void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view,
    413                                              Widget::Widgets* children) {
    414   NOTIMPLEMENTED();
    415 }
    416 
    417 // static
    418 void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view,
    419                                              Widget::Widgets* owned) {
    420   NOTIMPLEMENTED();
    421 }
    422 
    423 // static
    424 void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
    425                                              gfx::NativeView new_parent) {
    426   NOTIMPLEMENTED();
    427 }
    428 
    429 // static
    430 bool NativeWidgetPrivate::IsMouseButtonDown() {
    431   NOTIMPLEMENTED();
    432   return false;
    433 }
    434 
    435 // static
    436 bool NativeWidgetPrivate::IsTouchDown() {
    437   NOTIMPLEMENTED();
    438   return false;
    439 }
    440 
    441 // static
    442 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() {
    443   NOTIMPLEMENTED();
    444   return gfx::FontList();
    445 }
    446 
    447 }  // namespace internal
    448 }  // namespace views
    449