Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PLATFORM_UTIL_H_ |
| 6 | #define CHROME_BROWSER_PLATFORM_UTIL_H_ |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 7 | |
Avi Drissman | 9269d4ed | 2023-01-07 01:38:06 | [diff] [blame] | 8 | #include "base/functional/callback_forward.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 9 | #include "build/build_config.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 10 | #include "chrome/common/buildflags.h" |
Keren Zhu | c4ac783 | 2024-10-11 18:54:51 | [diff] [blame] | 11 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 12 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 076700e6 | 2009-04-01 18:41:23 | [diff] [blame] | 13 | |
Ivan Sandrk | c8e238b6 | 2019-03-18 15:00:02 | [diff] [blame] | 14 | class Browser; |
[email protected] | 59b2e32 | 2009-09-01 22:32:26 | [diff] [blame] | 15 | class GURL; |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 16 | class Profile; |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 17 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 18 | namespace base { |
| 19 | class FilePath; |
| 20 | } |
| 21 | |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 22 | namespace platform_util { |
| 23 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 24 | // Result of calling OpenFile() or OpenFolder() passed into OpenOperationResult. |
| 25 | enum OpenOperationResult { |
| 26 | OPEN_SUCCEEDED, |
| 27 | OPEN_FAILED_PATH_NOT_FOUND, // Specified path does not exist. |
| 28 | OPEN_FAILED_INVALID_TYPE, // Type of object found at path did not match what |
| 29 | // was expected. I.e. OpenFile was called on a |
| 30 | // folder or OpenFolder called on a file. |
| 31 | OPEN_FAILED_NO_HANLDER_FOR_FILE_TYPE, // There was no file handler capable of |
| 32 | // opening file. Only returned on |
| 33 | // ChromeOS. |
| 34 | OPEN_FAILED_FILE_ERROR, // Open operation failed due to some other file |
| 35 | // error. |
| 36 | }; |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 37 | |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 38 | // Type of item that is the target of the OpenItem() call. |
maksim.sisov | 4e6a58a6 | 2016-05-02 19:34:47 | [diff] [blame] | 39 | enum OpenItemType { |
| 40 | OPEN_FILE, |
| 41 | OPEN_FOLDER, |
maksim.sisov | 4e6a58a6 | 2016-05-02 19:34:47 | [diff] [blame] | 42 | }; |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 43 | |
| 44 | // Callback used with OpenFile and OpenFolder. |
Alexander Cooper | 71fa2b0 | 2020-07-16 17:49:36 | [diff] [blame] | 45 | typedef base::OnceCallback<void(OpenOperationResult)> OpenOperationCallback; |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 46 | |
| 47 | // Opens the item specified by |full_path|, which is expected to be the type |
| 48 | // indicated by |item_type| in the desktop's default manner. |
| 49 | // |callback| will be invoked on the UI thread with the result of the open |
| 50 | // operation. |
| 51 | // |
| 52 | // It is an error if the object at |full_path| does not match the intended type |
| 53 | // specified in |item_type|. This error will be reported to |callback|. |
| 54 | // |
| 55 | // Note: On all platforms, the user may be shown additional UI if there is no |
| 56 | // suitable handler for |full_path|. On Chrome OS, all errors will result in |
| 57 | // visible error messages iff |callback| is not specified. |
Orko Garai | ff9514b1 | 2025-01-09 18:10:13 | [diff] [blame] | 58 | // |
| 59 | // The |profile| is used to determine the running profile of file manager app in |
| 60 | // Chrome OS only. |profile| is not used in platforms other than Chrome OS. |
| 61 | // |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 62 | // Must be called on the UI thread. |
| 63 | void OpenItem(Profile* profile, |
| 64 | const base::FilePath& full_path, |
| 65 | OpenItemType item_type, |
Alexander Cooper | 71fa2b0 | 2020-07-16 17:49:36 | [diff] [blame] | 66 | OpenOperationCallback callback); |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 67 | |
| 68 | // Opens the folder containing the item specified by |full_path| in the |
Orko Garai | ff9514b1 | 2025-01-09 18:10:13 | [diff] [blame] | 69 | // desktop's default manner. If possible, the item will be selected. |
| 70 | // |
| 71 | // The |profile| is used to determine the running profile of file manager app in |
| 72 | // Chrome OS only. |profile| is not used in platforms other than Chrome OS. |
| 73 | // |
| 74 | // Must be called on the UI thread. |
asanka | 655d111 | 2015-03-07 05:33:41 | [diff] [blame] | 75 | void ShowItemInFolder(Profile* profile, const base::FilePath& full_path); |
[email protected] | de86a851 | 2009-05-28 20:29:40 | [diff] [blame] | 76 | |
[email protected] | 59b2e32 | 2009-09-01 22:32:26 | [diff] [blame] | 77 | // Open the given external protocol URL in the desktop's default manner. |
| 78 | // (For example, mailto: URLs in the default mail user agent.) |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 79 | // Must be called from the UI thread. |
Yuta Hijikata | ab5b1ca | 2025-03-06 06:13:04 | [diff] [blame] | 80 | #if BUILDFLAG(IS_CHROMEOS) |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 81 | void OpenExternal(Profile* profile, const GURL& url); |
David Roger | d283a17 | 2022-10-06 10:01:15 | [diff] [blame] | 82 | #else |
| 83 | void OpenExternal(const GURL& url); |
| 84 | #endif |
[email protected] | 59b2e32 | 2009-09-01 22:32:26 | [diff] [blame] | 85 | |
[email protected] | 076700e6 | 2009-04-01 18:41:23 | [diff] [blame] | 86 | // Get the top level window for the native view. This can return NULL. |
| 87 | gfx::NativeWindow GetTopLevel(gfx::NativeView view); |
| 88 | |
andresantoso | f8f9fd18 | 2014-11-15 01:14:39 | [diff] [blame] | 89 | // Returns a NativeView handle for parenting dialogs off |window|. This can be |
| 90 | // used to position a dialog using a NativeWindow, when a NativeView (e.g. |
| 91 | // browser tab) isn't available. |
| 92 | gfx::NativeView GetViewForWindow(gfx::NativeWindow window); |
| 93 | |
[email protected] | ba6680f | 2010-11-01 20:35:08 | [diff] [blame] | 94 | // Get the direct parent of |view|, may return NULL. |
| 95 | gfx::NativeView GetParent(gfx::NativeView view); |
| 96 | |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 97 | // Returns true if |window| is the foreground top level window. |
| 98 | bool IsWindowActive(gfx::NativeWindow window); |
| 99 | |
[email protected] | 9fa8af6 | 2010-06-03 17:15:22 | [diff] [blame] | 100 | // Activate the window, bringing it to the foreground top level. |
| 101 | void ActivateWindow(gfx::NativeWindow window); |
| 102 | |
[email protected] | bd1ad68 | 2009-05-15 22:19:17 | [diff] [blame] | 103 | // Returns true if the view is visible. The exact definition of this is |
| 104 | // platform-specific, but it is generally not "visible to the user", rather |
| 105 | // whether the view has the visible attribute set. |
| 106 | bool IsVisible(gfx::NativeView view); |
| 107 | |
Xiaohan Wang | 55ae2c01 | 2022-01-20 21:49:11 | [diff] [blame] | 108 | #if BUILDFLAG(IS_MAC) |
Avi Drissman | 0ad8085 | 2022-07-22 18:47:47 | [diff] [blame] | 109 | // On the Mac, back and forward swipe gestures can be triggered using a scroll |
| 110 | // gesture, if enabled in System Preferences. This function returns true if the |
| 111 | // feature is enabled, and false otherwise. |
[email protected] | 895585e | 2012-04-19 18:24:07 | [diff] [blame] | 112 | bool IsSwipeTrackingFromScrollEventsEnabled(); |
Wei Li | 280b0d2 | 2021-02-10 20:23:10 | [diff] [blame] | 113 | |
| 114 | // Returns the active window which accepts keyboard inputs. |
Avi Drissman | 1bade823 | 2025-03-19 18:00:32 | [diff] [blame] | 115 | gfx::NativeWindow GetActiveWindow(); |
Keren Zhu | c4ac783 | 2024-10-11 18:54:51 | [diff] [blame] | 116 | |
| 117 | // Returns the screen bounds of a window. Top left screen corner is (0, 0). |
| 118 | // TODO(crbug.com/365733574): used for debugging the misplaced bubble issue on |
| 119 | // mac fullscreen. |
| 120 | gfx::Rect GetWindowScreenBounds(gfx::NativeWindow window); |
[email protected] | 895585e | 2012-04-19 18:24:07 | [diff] [blame] | 121 | #endif |
| 122 | |
Ivan Sandrk | c8e238b6 | 2019-03-18 15:00:02 | [diff] [blame] | 123 | // Returns true if the given browser window is in locked fullscreen mode |
| 124 | // (a special type of fullscreen where the user is locked into one browser |
| 125 | // window). |
| 126 | bool IsBrowserLockedFullscreen(const Browser* browser); |
| 127 | |
[email protected] | 7f0a3efa | 2013-12-12 17:16:12 | [diff] [blame] | 128 | } // namespace platform_util |
[email protected] | 1a9e11dc | 2009-03-24 20:40:44 | [diff] [blame] | 129 | |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 130 | #endif // CHROME_BROWSER_PLATFORM_UTIL_H_ |