• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ROSEN_WINDOW_H
17 #define OHOS_ROSEN_WINDOW_H
18 
19 #include <refbase.h>
20 #include <parcel.h>
21 #include <pixel_map.h>
22 #include <iremote_object.h>
23 
24 #include "wm_common.h"
25 #include "window_option.h"
26 
27 class NativeValue;
28 class NativeEngine;
29 namespace OHOS::MMI {
30     class PointerEvent;
31     class KeyEvent;
32     class AxisEvent;
33 }
34 namespace OHOS::AppExecFwk {
35     class Configuration;
36     class Ability;
37 }
38 
39 namespace OHOS::AbilityRuntime {
40     class AbilityContext;
41     class Context;
42 }
43 
44 namespace OHOS::AAFwk {
45     class Want;
46 }
47 
48 namespace OHOS::Ace {
49     class UIContent;
50 }
51 
52 namespace OHOS {
53 namespace Rosen {
54 using NotifyNativeWinDestroyFunc = std::function<void(std::string windowName)>;
55 class RSSurfaceNode;
56 
57 class IWindowLifeCycle : virtual public RefBase {
58 public:
AfterForeground()59     virtual void AfterForeground() {}
AfterBackground()60     virtual void AfterBackground() {}
AfterFocused()61     virtual void AfterFocused() {}
AfterUnfocused()62     virtual void AfterUnfocused() {}
ForegroundFailed(int32_t ret)63     virtual void ForegroundFailed(int32_t ret) {}
AfterActive()64     virtual void AfterActive() {}
AfterInactive()65     virtual void AfterInactive() {}
66 };
67 
68 class IWindowChangeListener : virtual public RefBase {
69 public:
OnSizeChange(Rect rect,WindowSizeChangeReason reason)70     virtual void OnSizeChange(Rect rect, WindowSizeChangeReason reason) {}
OnModeChange(WindowMode mode)71     virtual void OnModeChange(WindowMode mode) {}
72 };
73 
74 class IAvoidAreaChangedListener : virtual public RefBase {
75 public:
OnAvoidAreaChanged(const AvoidArea avoidArea,AvoidAreaType type)76     virtual void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) {}
77 };
78 
79 class IWindowDragListener : virtual public RefBase {
80 public:
OnDrag(int32_t x,int32_t y,DragEvent event)81     virtual void OnDrag(int32_t x, int32_t y, DragEvent event) {}
82 };
83 
84 class IDisplayMoveListener : virtual public RefBase {
85 public:
OnDisplayMove(DisplayId from,DisplayId to)86     virtual void OnDisplayMove(DisplayId from, DisplayId to) {}
87 };
88 
89 class IDispatchInputEventListener : virtual public RefBase {
90 public:
91     virtual void OnDispatchPointerEvent(std::shared_ptr<MMI::PointerEvent>& inputEvent) = 0;
92     virtual void OnDispatchKeyEvent(std::shared_ptr<MMI::KeyEvent>& keyEvent) = 0;
93 };
94 
95 class OccupiedAreaChangeInfo : public Parcelable {
96 public:
97     OccupiedAreaChangeInfo() = default;
OccupiedAreaChangeInfo(OccupiedAreaType type,Rect rect)98     OccupiedAreaChangeInfo(OccupiedAreaType type, Rect rect) : type_(type), rect_(rect) {};
99     ~OccupiedAreaChangeInfo() = default;
100 
101     virtual bool Marshalling(Parcel& parcel) const override;
102     static OccupiedAreaChangeInfo* Unmarshalling(Parcel& parcel);
103 
104     OccupiedAreaType type_ = OccupiedAreaType::TYPE_INPUT;
105     Rect rect_ = { 0, 0, 0, 0 };
106 };
107 
108 class IOccupiedAreaChangeListener : virtual public RefBase {
109 public:
OnSizeChange(const sptr<OccupiedAreaChangeInfo> & info)110     virtual void OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info) {}
111 };
112 
113 class IAceAbilityHandler : virtual public RefBase {
114 public:
115     virtual void SetBackgroundColor(uint32_t color) = 0;
116     virtual uint32_t GetBackgroundColor() = 0;
117 };
118 
119 class IInputEventConsumer {
120 public:
121     IInputEventConsumer() = default;
122     virtual ~IInputEventConsumer() = default;
123     virtual bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const = 0;
124     virtual bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const = 0;
125     virtual bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const = 0;
126 };
127 
128 class ITouchOutsideListener : virtual public RefBase {
129 public:
OnTouchOutside()130     virtual void OnTouchOutside() const {}
131 };
132 
133 class IAnimationTransitionController : virtual public RefBase {
134 public:
135     virtual void AnimationForShown() = 0;
136     virtual void AnimationForHidden() = 0;
137 };
138 
139 class IScreenshotListener : virtual public RefBase {
140 public:
OnScreenshot()141     virtual void OnScreenshot() {}
142 };
143 
144 class IDialogTargetTouchListener : virtual public RefBase {
145 public:
OnDialogTargetTouch()146     virtual void OnDialogTargetTouch() const {}
147 };
148 
149 class IDialogDeathRecipientListener : virtual public RefBase {
150 public:
151     virtual void OnDialogDeathRecipient() const = 0;
152 };
153 
154 class Window : public RefBase {
155 public:
156     /**
157      * @brief create window, include main_window/sub_window/system_window
158      *
159      * @param windowName window name, identify window instance
160      * @param option window propertion
161      * @param context ability context
162      * @return sptr<Window> If create window success,return window instance;Otherwise, return nullptr
163      */
164     static sptr<Window> Create(const std::string& windowName,
165         sptr<WindowOption>& option, const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
166     /**
167      * @brief find window by windowName
168      *
169      * @param windowName
170      * @return sptr<Window> Return the window instance founded
171      */
172     static sptr<Window> Find(const std::string& windowName);
173     /**
174      * @brief Get the final show window by context. Its implemented in api8
175      *
176      * @param context Indicates the context on which the window depends
177      * @return sptr<Window>
178      */
179     static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
180     /**
181      * @brief Get the final show window by id. Its implemented in api8
182      *
183      * @param mainWinId main window id?
184      * @return sptr<Window>
185      */
186     static sptr<Window> GetTopWindowWithId(uint32_t mainWinId);
187     /**
188      * @brief Get the all sub windows by parent
189      *
190      * @param parentId parent window id
191      * @return std::vector<sptr<Window>>
192      */
193     static std::vector<sptr<Window>> GetSubWindow(uint32_t parentId);
194 
195     /**
196      * @brief Update configuration for all windows
197      *
198      * @param configuration configuration for app
199      */
200     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
201     virtual std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const = 0;
202     virtual const std::shared_ptr<AbilityRuntime::Context> GetContext() const = 0;
203     /**
204      * @brief Get the window show rect
205      *
206      * @return Rect window rect
207      */
208     virtual Rect GetRect() const = 0;
209     virtual Rect GetRequestRect() const = 0;
210     /**
211      * @brief Get the window type
212      *
213      * @return WindowType window type
214      */
215     virtual WindowType GetType() const = 0;
216     virtual WindowMode GetMode() const = 0;
217     virtual float GetAlpha() const = 0;
218     virtual const std::string& GetWindowName() const = 0;
219     virtual uint32_t GetWindowId() const = 0;
220     virtual uint32_t GetWindowFlags() const = 0;
221     virtual WindowState GetWindowState() const = 0;
222     virtual WMError SetFocusable(bool isFocusable) = 0;
223     virtual bool GetFocusable() const = 0;
224     virtual WMError SetTouchable(bool isTouchable) = 0;
225     virtual bool GetTouchable() const = 0;
226     virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const = 0;
227     /**
228      * @brief judge this window is full screen.
229      *
230      * @return true If SetFullScreen(true) is called , return true.
231      * @return false default return false
232      */
233     virtual bool IsFullScreen() const = 0;
234     /**
235      * @brief judge window layout is full screen
236      *
237      * @return true this window layout is full screen
238      * @return false this window layout is not full screen
239      */
240     virtual bool IsLayoutFullScreen() const = 0;
241     /**
242      * @brief Set the Window Type
243      *
244      * @param type window type
245      * @return WMError
246      */
247     virtual WMError SetWindowType(WindowType type) = 0;
248     /**
249      * @brief Set the Window Mode
250      *
251      * @param mode window mode
252      * @return WMError
253      */
254     virtual WMError SetWindowMode(WindowMode mode) = 0;
255     virtual void SetAlpha(float alpha) = 0;
256     virtual void SetTransform(const Transform& trans) = 0;
257     virtual const Transform& GetTransform() const = 0;
258     virtual WMError AddWindowFlag(WindowFlag flag) = 0;
259     virtual WMError RemoveWindowFlag(WindowFlag flag) = 0;
260     virtual WMError SetWindowFlags(uint32_t flags) = 0;
261     /**
262      * @brief Set the System Bar(include status bar and nav bar) Property
263      *
264      * @param type WINDOW_TYPE_STATUS_BAR or WINDOW_TYPE_NAVIGATION_BAR
265      * @param property system bar prop,include content color, background color
266      * @return WMError
267      */
268     virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) = 0;
269     /**
270      * @brief Get the Avoid Area By Type object
271      *
272      * @param type avoid area type.@see reference
273      * @param avoidArea
274      * @return WMError
275      */
276     virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) = 0;
277     /**
278      * @brief Set this window layout full screen, with hide status bar and nav bar above on this window
279      *
280      * @param status
281      * @return WMError
282      */
283     virtual WMError SetLayoutFullScreen(bool status) = 0;
284     /**
285      * @brief Set this window full screen, with hide status bar and nav bar
286      *
287      * @param status if true, hide status bar and nav bar; Otherwise, show status bar and nav bar
288      * @return WMError
289      */
290     virtual WMError SetFullScreen(bool status) = 0;
291     /**
292      * @brief destroy window
293      *
294      * @return WMError
295      */
296     virtual WMError Destroy() = 0;
297     virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) = 0;
298     virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false) = 0;
299     /**
300      * @brief move the window to (x, y)
301      *
302      * @param x
303      * @param y
304      * @return WMError
305      */
306     virtual WMError MoveTo(int32_t x, int32_t y) = 0;
307     /**
308      * @brief resize the window instance (w,h)
309      *
310      * @param width
311      * @param height
312      * @return WMError
313      */
314     virtual WMError Resize(uint32_t width, uint32_t height) = 0;
315     /**
316      * @brief Set the screen always on
317      *
318      * @param keepScreenOn
319      * @return WMError
320      */
321     virtual WMError SetKeepScreenOn(bool keepScreenOn) = 0;
322     virtual bool IsKeepScreenOn() const = 0;
323     virtual WMError SetTurnScreenOn(bool turnScreenOn) = 0;
324     virtual bool IsTurnScreenOn() const = 0;
325     virtual WMError SetBackgroundColor(const std::string& color) = 0;
326     virtual WMError SetTransparent(bool isTransparent) = 0;
327     virtual bool IsTransparent() const = 0;
328     virtual WMError SetBrightness(float brightness) = 0;
329     virtual float GetBrightness() const = 0;
330     virtual WMError SetCallingWindow(uint32_t windowId) = 0;
331     virtual void SetPrivacyMode(bool isPrivacyMode) = 0;
332     virtual bool IsPrivacyMode() const = 0;
333     virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) = 0;
334     virtual WMError BindDialogTarget(sptr<IRemoteObject> targetToken) = 0;
335     virtual void SetSnapshotSkip(bool isSkip) = 0;
336 
337     // window effect
338     virtual WMError SetCornerRadius(float cornerRadius) = 0;
339     virtual WMError SetShadowRadius(float radius) = 0;
340     virtual WMError SetShadowColor(std::string color) = 0;
341     virtual void SetShadowOffsetX(float offsetX) = 0;
342     virtual void SetShadowOffsetY(float offsetY) = 0;
343     virtual WMError SetBlur(float radius) = 0;
344     virtual WMError SetBackdropBlur(float radius) = 0;
345     virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) = 0;
346 
347     virtual WMError RequestFocus() const = 0;
348     virtual bool IsFocused() const = 0;
349     virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) = 0;
350     virtual void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) = 0;
351     virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) = 0;
352     virtual void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& inputEvent) = 0;
353     virtual void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) = 0;
354     virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) = 0;
355     /**
356      * @brief register window lifecycle listener.
357      *
358      * @param listener
359      */
360     virtual bool RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) = 0;
361     virtual bool RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) = 0;
362     virtual bool UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) = 0;
363     virtual bool UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) = 0;
364     virtual bool RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0;
365     virtual bool UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0;
366     virtual bool RegisterDragListener(const sptr<IWindowDragListener>& listener) = 0;
367     virtual bool UnregisterDragListener(const sptr<IWindowDragListener>& listener) = 0;
368     virtual bool RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0;
369     virtual bool UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0;
370     virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) = 0;
371     virtual bool RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) = 0;
372     virtual bool UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) = 0;
373     virtual bool RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) = 0;
374     virtual bool UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) = 0;
375     virtual bool RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) = 0;
376     virtual bool RegisterScreenshotListener(const sptr<IScreenshotListener>& listener) = 0;
377     virtual bool UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener) = 0;
378     virtual bool RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) = 0;
379     virtual bool UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) = 0;
380     virtual void RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) = 0;
381     virtual void UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) = 0;
382     virtual void NotifyTouchDialogTarget() = 0;
383     virtual void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) = 0;
384     /**
385      * @brief set window ui content
386      *
387      * @param contentInfo content info path
388      * @param engine
389      * @param storage
390      * @param isDistributed
391      * @param ability
392      * @return WMError
393      */
394     virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine,
395         NativeValue* storage, bool isDistributed = false, AppExecFwk::Ability* ability = nullptr) = 0;
396     virtual std::string GetContentInfo() = 0;
397     virtual Ace::UIContent* GetUIContent() const = 0;
398     virtual void OnNewWant(const AAFwk::Want& want) = 0;
399     virtual void SetRequestedOrientation(Orientation) = 0;
400     virtual Orientation GetRequestedOrientation() = 0;
401     virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) = 0;
402     virtual uint32_t GetRequestModeSupportInfo() const = 0;
403     virtual WMError SetTouchHotAreas(const std::vector<Rect>& rects) = 0;
404     virtual void GetRequestedTouchHotAreas(std::vector<Rect>& rects) const = 0;
405     virtual bool IsMainHandlerAvailable() const = 0;
406     virtual WMError SetAPPWindowLabel(const std::string& label) = 0;
407     virtual WMError SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon) = 0;
408 
409     /**
410      * @brief disable main window decoration. It must be callled before loadContent.
411      *
412      */
413     virtual void DisableAppWindowDecor() = 0;
414     /**
415      * @brief return window decoration is enabled. It is called by ACE
416      *
417      * @return true means window decoration is enabled. Otherwise disabled
418      */
419     virtual bool IsDecorEnable() const = 0;
420     /**
421      * @brief maximize the main window. It is called by ACE when maximize button is clicked.
422      *
423      * @return WMError
424      */
425     virtual WMError Maximize() = 0;
426     /**
427      * @brief minimize the main window. It is called by ACE when minimize button is clicked.
428      *
429      * @return WMError
430      */
431     virtual WMError Minimize() = 0;
432     /**
433      * @brief recovery the main window. It is called by ACE when recovery button is clicked.
434      *
435      * @return WMError
436      */
437     virtual WMError Recover() = 0;
438     /**
439      * @brief close the main window. It is called by ACE when close button is clicked.
440      *
441      * @return WMError
442      */
443     virtual WMError Close() = 0;
444     /**
445      * @brief start move main window. It is called by ACE when title is moved.
446      *
447      */
448     virtual void StartMove() = 0;
449     virtual void SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel) = 0;
450 
451     // colorspace, gamut
452     virtual bool IsSupportWideGamut() = 0;
453     virtual void SetColorSpace(ColorSpace colorSpace) = 0;
454     virtual ColorSpace GetColorSpace() = 0;
455 
456     virtual void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) = 0;
457     /**
458      * @brief window snapshot
459      *
460      * @return std::shared_ptr<Media::PixelMap> snapshot pixel
461      */
462     virtual std::shared_ptr<Media::PixelMap> Snapshot() = 0;
463 
464     /**
465      * @brief Handle and notify memory level.
466      *
467      * @param level memory level
468      * @return the error code of window
469      */
470     virtual WMError NotifyMemoryLevel(int32_t level) const = 0;
471 
472     /**
473      * @brief Update configuration for all windows
474      *
475      * @param configuration configuration for app
476      */
477     virtual bool IsAllowHaveSystemSubWindow() = 0;
478 };
479 }
480 }
481 #endif // OHOS_ROSEN_WINDOW_H
482