Home | History | Annotate | Download | only in ios
      1 /*
      2  * Copyright 2016 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #import <UIKit/UIKit.h>
      9 #include "SkCanvas.h"
     10 #include "SkGraphics.h"
     11 #import "SkEventNotifier.h"
     12 #include "SkOSMenu.h"
     13 #include "SkTime.h"
     14 #include "SkTypes.h"
     15 #import "SkUIView.h"
     16 #include "SkWindow.h"
     17 
     18 #define kINVAL_UIVIEW_EventType "inval-uiview"
     19 
     20 SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
     21     fInvalEventIsPending = false;
     22     fNotifier = [[SkEventNotifier alloc] init];
     23 }
     24 SkOSWindow::~SkOSWindow() {
     25     [(SkEventNotifier*)fNotifier release];
     26 }
     27 
     28 void SkOSWindow::onHandleInval(const SkIRect& r) {
     29     if (!fInvalEventIsPending) {
     30         fInvalEventIsPending = true;
     31         (new SkEvent(kINVAL_UIVIEW_EventType, this->getSinkID()))->post();
     32     }
     33 }
     34 
     35 bool SkOSWindow::onEvent(const SkEvent& evt) {
     36     if (evt.isType(kINVAL_UIVIEW_EventType)) {
     37         fInvalEventIsPending = false;
     38         const SkIRect& r = this->getDirtyBounds();
     39         [(SkUIView*)fHWND postInvalWithRect:&r];
     40         return true;
     41     }
     42     if ([(SkUIView*)fHWND onHandleEvent:evt]) {
     43         return true;
     44     }
     45     return this->INHERITED::onEvent(evt);
     46 }
     47 
     48 void SkOSWindow::onSetTitle(const char title[]) {
     49     [(SkUIView*)fHWND setSkTitle:title];
     50 }
     51 
     52 void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
     53     [(SkUIView*)fHWND onAddMenu:menu];
     54 }
     55 
     56 void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
     57     [(SkUIView*)fHWND onUpdateMenu:menu];
     58 }
     59 
     60 bool SkOSWindow::attach(SkBackEndTypes /* attachType */,
     61                         int /* msaaSampleCount */,
     62                         bool /* deepColor */,
     63                         AttachmentInfo* info) {
     64     [(SkUIView*)fHWND getAttachmentInfo:info];
     65     bool success = true;
     66     return success;
     67 }
     68 
     69 void SkOSWindow::release() {}
     70 
     71 void SkOSWindow::present() {
     72 }
     73