1 // Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be found 3 // in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_VIEWS_VIEW_UTIL_H_ 6 #define CEF_LIBCEF_BROWSER_VIEWS_VIEW_UTIL_H_ 7 #pragma once 8 9 #include "include/views/cef_view.h" 10 #include "include/views/cef_window.h" 11 12 #include "ui/views/view.h" 13 14 namespace display { 15 class Display; 16 } 17 18 namespace gfx { 19 class Point; 20 } 21 22 namespace views { 23 class Widget; 24 } 25 26 #define CEF_REQUIRE_VALID_RETURN(ret) \ 27 if (!ParentClass::IsValid()) \ 28 return ret; 29 30 #define CEF_REQUIRE_VALID_RETURN_VOID() \ 31 if (!ParentClass::IsValid()) \ 32 return; 33 34 // The below functions manage the relationship between CefView and views::View 35 // instances. See comments in view_impl.h for a usage overview. 36 37 namespace view_util { 38 39 // Default values. 40 extern const SkColor kDefaultBackgroundColor; 41 extern const char kDefaultFontList[]; 42 43 // Called when a CefView is initialized to create the initial association 44 // between the underlying views::View and |view|. The CefView owns the 45 // views::View at this stage. 46 void Register(CefRefPtr<CefView> view); 47 48 // Returns the CefView object associated with the specified |view|. If no 49 // CefView is associated with |view| and |find_known_parent| is true then this 50 // function will return the closest parent views::View with an associated 51 // CefView. 52 CefRefPtr<CefView> GetFor(const views::View* view, bool find_known_parent); 53 54 // Returns the views::View object associated with the specified |view|. 55 // Ownership of the views::View object does not change. 56 views::View* GetFor(CefRefPtr<CefView> view); 57 58 // Returns the views::View object associated with the specified |view| and 59 // passes ownership to the caller. The views::View object should then be passed 60 // to another views::View via views::View or views::LayoutManager methods. The 61 // views::View will keep a ref-counted reference to |view|, and |view| will keep 62 // an un-owned reference to the views::View. These references will reset when 63 // the views::View object is deleted or when ResumeOwnership() is called. 64 std::unique_ptr<views::View> PassOwnership(CefRefPtr<CefView> view) 65 WARN_UNUSED_RESULT; 66 67 // Causes |view| to resume ownership of the views::View object. Should be called 68 // after removing the views::View object from its previous parent. 69 void ResumeOwnership(CefRefPtr<CefView> view); 70 71 // Returns the Window associated with |widget|. 72 CefRefPtr<CefWindow> GetWindowFor(views::Widget* widget); 73 74 // Returns the Display nearest |point|. Set |input_pixel_coords| to true if 75 // |point| is in pixel coordinates instead of density independent pixels (DIP). 76 display::Display GetDisplayNearestPoint(const gfx::Point& point, 77 bool input_pixel_coords); 78 79 // Returns the Display that most closely intersects |bounds|. Set 80 // |input_pixel_coords| to true if |bounds| is in pixel coordinates instead of 81 // density independent pixels (DIP). 82 display::Display GetDisplayMatchingBounds(const gfx::Rect& bounds, 83 bool input_pixel_coords); 84 85 // Convert |point| from pixel coordinates to density independent pixels (DIP) 86 // using |device_scale_factor|. 87 void ConvertPointFromPixels(gfx::Point* point, int device_scale_factor); 88 89 // Convert |point| to pixel coordinates from density independent pixels (DIP) 90 // using |device_scale_factor|. 91 void ConvertPointToPixels(gfx::Point* point, int device_scale_factor); 92 93 // Convert |point| from |view| to screen coordinates. If |output_pixel_coords| 94 // is true then |point| will be output in pixel coordinates instead of density 95 // independent pixels (DIP). Returns false if |view| does not currently belong 96 // to a Widget. 97 bool ConvertPointToScreen(views::View* view, 98 gfx::Point* point, 99 bool output_pixel_coords); 100 101 // Convert |point| from screen to |view| coordinates. Set |input_pixel_coords| 102 // to true when |point| is being input in pixel coordinates instead of density 103 // independent pixels (DIP). Returns false if |view| does not currently belong 104 // to a Widget. 105 bool ConvertPointFromScreen(views::View* view, 106 gfx::Point* point, 107 bool input_pixel_coords); 108 109 // Convert |point| from |view| to window (Widget) coordinates. Returns false if 110 // |view| does not currently belong to a Widget. 111 bool ConvertPointToWindow(views::View* view, gfx::Point* point); 112 113 // Convert |point| from window (Widget) to |view| coordinates. Returns false if 114 // |view| does not currently belong to a Widget. 115 bool ConvertPointFromWindow(views::View* view, gfx::Point* point); 116 117 // Returns the native window handle for |widget|. May return nullptr. 118 gfx::NativeWindow GetNativeWindow(views::Widget* widget); 119 120 // Returns the native view handle for |widget|. May return nullptr. 121 gfx::NativeView GetNativeView(views::Widget* widget); 122 123 // Returns the platform window handle for |widget|. May return nullptr. 124 CefWindowHandle GetWindowHandle(views::Widget* widget); 125 126 } // namespace view_util 127 128 #endif // CEF_LIBCEF_BROWSER_VIEWS_VIEW_UTIL_H_ 129