github.com/ckxng/wakeup@v0.0.0-20190105202853-90356a5f5a15/include/internal/cef_mac.h (about)

     1  // Copyright (c) 2010 Marshall A. Greenblatt. All rights reserved.
     2  //
     3  // Redistribution and use in source and binary forms, with or without
     4  // modification, are permitted provided that the following conditions are
     5  // met:
     6  //
     7  //    * Redistributions of source code must retain the above copyright
     8  // notice, this list of conditions and the following disclaimer.
     9  //    * Redistributions in binary form must reproduce the above
    10  // copyright notice, this list of conditions and the following disclaimer
    11  // in the documentation and/or other materials provided with the
    12  // distribution.
    13  //    * Neither the name of Google Inc. nor the name Chromium Embedded
    14  // Framework nor the names of its contributors may be used to endorse
    15  // or promote products derived from this software without specific prior
    16  // written permission.
    17  //
    18  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    19  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    20  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    21  // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    22  // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    23  // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    24  // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    25  // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    26  // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    27  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    28  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    29  
    30  
    31  #ifndef CEF_INCLUDE_INTERNAL_CEF_MAC_H_
    32  #define CEF_INCLUDE_INTERNAL_CEF_MAC_H_
    33  #pragma once
    34  
    35  #if defined(OS_MACOSX)
    36  #include <pthread.h>
    37  #include "include/internal/cef_types_mac.h"
    38  #include "include/internal/cef_types_wrappers.h"
    39  
    40  // Atomic increment and decrement.
    41  inline long CefAtomicIncrement(long volatile *pDest) {  // NOLINT(runtime/int)
    42    return __sync_add_and_fetch(pDest, 1);
    43  }
    44  inline long CefAtomicDecrement(long volatile *pDest) {  // NOLINT(runtime/int)
    45    return __sync_sub_and_fetch(pDest, 1);
    46  }
    47  
    48  // Critical section wrapper.
    49  class CefCriticalSection {
    50   public:
    51    CefCriticalSection() {
    52      pthread_mutexattr_init(&attr_);
    53      pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
    54      pthread_mutex_init(&lock_, &attr_);
    55    }
    56    virtual ~CefCriticalSection() {
    57      pthread_mutex_destroy(&lock_);
    58      pthread_mutexattr_destroy(&attr_);
    59    }
    60    void Lock() {
    61      pthread_mutex_lock(&lock_);
    62    }
    63    void Unlock() {
    64      pthread_mutex_unlock(&lock_);
    65    }
    66  
    67    pthread_mutex_t lock_;
    68    pthread_mutexattr_t attr_;
    69  };
    70  
    71  // Handle types.
    72  #define CefCursorHandle cef_cursor_handle_t
    73  #define CefEventHandle cef_event_handle_t
    74  #define CefWindowHandle cef_window_handle_t
    75  #define CefTextInputContext cef_text_input_context_t
    76  
    77  struct CefMainArgsTraits {
    78    typedef cef_main_args_t struct_type;
    79  
    80    static inline void init(struct_type* s) {}
    81    static inline void clear(struct_type* s) {}
    82  
    83    static inline void set(const struct_type* src, struct_type* target,
    84        bool copy) {
    85      target->argc = src->argc;
    86      target->argv = src->argv;
    87    }
    88  };
    89  
    90  // Class representing CefExecuteProcess arguments.
    91  class CefMainArgs : public CefStructBase<CefMainArgsTraits> {
    92   public:
    93    typedef CefStructBase<CefMainArgsTraits> parent;
    94  
    95    CefMainArgs() : parent() {}
    96    explicit CefMainArgs(const cef_main_args_t& r) : parent(r) {}
    97    explicit CefMainArgs(const CefMainArgs& r) : parent(r) {}
    98    CefMainArgs(int argc, char** argv) : parent() {
    99      this->argc = argc;
   100      this->argv = argv;
   101    }
   102  };
   103  
   104  struct CefWindowInfoTraits {
   105    typedef cef_window_info_t struct_type;
   106  
   107    static inline void init(struct_type* s) {}
   108  
   109    static inline void clear(struct_type* s) {
   110      cef_string_clear(&s->window_name);
   111    }
   112  
   113    static inline void set(const struct_type* src, struct_type* target,
   114        bool copy) {
   115      target->view = src->view;
   116      target->parent_view = src->parent_view;
   117      cef_string_set(src->window_name.str, src->window_name.length,
   118          &target->window_name, copy);
   119      target->x = src->x;
   120      target->y = src->y;
   121      target->width = src->width;
   122      target->height = src->height;
   123      target->hidden = src->hidden;
   124      target->transparent_painting = src->transparent_painting;
   125      target->window_rendering_disabled = src->window_rendering_disabled;
   126    }
   127  };
   128  
   129  // Class representing window information.
   130  class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> {
   131   public:
   132    typedef CefStructBase<CefWindowInfoTraits> parent;
   133  
   134    CefWindowInfo() : parent() {}
   135    explicit CefWindowInfo(const cef_window_info_t& r) : parent(r) {}
   136    explicit CefWindowInfo(const CefWindowInfo& r) : parent(r) {}
   137  
   138    void SetAsChild(CefWindowHandle ParentView, int x, int y, int width,
   139                    int height) {
   140      parent_view = ParentView;
   141      this->x = x;
   142      this->y = y;
   143      this->width = width;
   144      this->height = height;
   145      hidden = false;
   146    }
   147  
   148    void SetTransparentPainting(bool transparentPainting) {
   149      transparent_painting = transparentPainting;
   150    }
   151  
   152    void SetAsOffScreen(NSView* view) {
   153      window_rendering_disabled = true;
   154      parent_view = view;
   155    }
   156  };
   157  
   158  #endif  // OS_MACOSX
   159  
   160  #endif  // CEF_INCLUDE_INTERNAL_CEF_MAC_H_