blob: c6ad3b4522497c0d76a851ab68dcc9e9cc506d2b [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
[email protected]1a9e11dc2009-03-24 20:40:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]14a000d2010-04-29 21:44:245#ifndef CHROME_BROWSER_PLATFORM_UTIL_H_
6#define CHROME_BROWSER_PLATFORM_UTIL_H_
[email protected]1a9e11dc2009-03-24 20:40:447
Avi Drissman9269d4ed2023-01-07 01:38:068#include "base/functional/callback_forward.h"
avib896c712015-12-26 02:10:439#include "build/build_config.h"
Scott Violet6200d332018-02-23 21:29:2310#include "chrome/common/buildflags.h"
Keren Zhuc4ac7832024-10-11 18:54:5111#include "ui/gfx/geometry/rect.h"
[email protected]08397d52011-02-05 01:53:3812#include "ui/gfx/native_widget_types.h"
[email protected]076700e62009-04-01 18:41:2313
Ivan Sandrkc8e238b62019-03-18 15:00:0214class Browser;
[email protected]59b2e322009-09-01 22:32:2615class GURL;
[email protected]7f0a3efa2013-12-12 17:16:1216class Profile;
[email protected]1a9e11dc2009-03-24 20:40:4417
[email protected]a3ef4832013-02-02 05:12:3318namespace base {
19class FilePath;
20}
21
[email protected]1a9e11dc2009-03-24 20:40:4422namespace platform_util {
23
asanka655d1112015-03-07 05:33:4124// Result of calling OpenFile() or OpenFolder() passed into OpenOperationResult.
25enum 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]1a9e11dc2009-03-24 20:40:4437
asanka655d1112015-03-07 05:33:4138// Type of item that is the target of the OpenItem() call.
maksim.sisov4e6a58a62016-05-02 19:34:4739enum OpenItemType {
40 OPEN_FILE,
41 OPEN_FOLDER,
maksim.sisov4e6a58a62016-05-02 19:34:4742};
asanka655d1112015-03-07 05:33:4143
44// Callback used with OpenFile and OpenFolder.
Alexander Cooper71fa2b02020-07-16 17:49:3645typedef base::OnceCallback<void(OpenOperationResult)> OpenOperationCallback;
asanka655d1112015-03-07 05:33:4146
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 Garaiff9514b12025-01-09 18:10:1358//
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//
asanka655d1112015-03-07 05:33:4162// Must be called on the UI thread.
63void OpenItem(Profile* profile,
64 const base::FilePath& full_path,
65 OpenItemType item_type,
Alexander Cooper71fa2b02020-07-16 17:49:3666 OpenOperationCallback callback);
asanka655d1112015-03-07 05:33:4167
68// Opens the folder containing the item specified by |full_path| in the
Orko Garaiff9514b12025-01-09 18:10:1369// 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.
asanka655d1112015-03-07 05:33:4175void ShowItemInFolder(Profile* profile, const base::FilePath& full_path);
[email protected]de86a8512009-05-28 20:29:4076
[email protected]59b2e322009-09-01 22:32:2677// 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]7f0a3efa2013-12-12 17:16:1279// Must be called from the UI thread.
Yuta Hijikataab5b1ca2025-03-06 06:13:0480#if BUILDFLAG(IS_CHROMEOS)
[email protected]7f0a3efa2013-12-12 17:16:1281void OpenExternal(Profile* profile, const GURL& url);
David Rogerd283a172022-10-06 10:01:1582#else
83void OpenExternal(const GURL& url);
84#endif
[email protected]59b2e322009-09-01 22:32:2685
[email protected]076700e62009-04-01 18:41:2386// Get the top level window for the native view. This can return NULL.
87gfx::NativeWindow GetTopLevel(gfx::NativeView view);
88
andresantosof8f9fd182014-11-15 01:14:3989// 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.
92gfx::NativeView GetViewForWindow(gfx::NativeWindow window);
93
[email protected]ba6680f2010-11-01 20:35:0894// Get the direct parent of |view|, may return NULL.
95gfx::NativeView GetParent(gfx::NativeView view);
96
[email protected]d2cc6ed2009-04-24 00:26:1797// Returns true if |window| is the foreground top level window.
98bool IsWindowActive(gfx::NativeWindow window);
99
[email protected]9fa8af62010-06-03 17:15:22100// Activate the window, bringing it to the foreground top level.
101void ActivateWindow(gfx::NativeWindow window);
102
[email protected]bd1ad682009-05-15 22:19:17103// 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.
106bool IsVisible(gfx::NativeView view);
107
Xiaohan Wang55ae2c012022-01-20 21:49:11108#if BUILDFLAG(IS_MAC)
Avi Drissman0ad80852022-07-22 18:47:47109// 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]895585e2012-04-19 18:24:07112bool IsSwipeTrackingFromScrollEventsEnabled();
Wei Li280b0d22021-02-10 20:23:10113
114// Returns the active window which accepts keyboard inputs.
Avi Drissman1bade8232025-03-19 18:00:32115gfx::NativeWindow GetActiveWindow();
Keren Zhuc4ac7832024-10-11 18:54:51116
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.
120gfx::Rect GetWindowScreenBounds(gfx::NativeWindow window);
[email protected]895585e2012-04-19 18:24:07121#endif
122
Ivan Sandrkc8e238b62019-03-18 15:00:02123// 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).
126bool IsBrowserLockedFullscreen(const Browser* browser);
127
[email protected]7f0a3efa2013-12-12 17:16:12128} // namespace platform_util
[email protected]1a9e11dc2009-03-24 20:40:44129
[email protected]14a000d2010-04-29 21:44:24130#endif // CHROME_BROWSER_PLATFORM_UTIL_H_