michael@0: /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsIWidget_h__ michael@0: #define nsIWidget_h__ michael@0: michael@0: #include "nsISupports.h" michael@0: #include "nsColor.h" michael@0: #include "nsRect.h" michael@0: #include "nsStringGlue.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsWidgetInitData.h" michael@0: #include "nsTArray.h" michael@0: #include "nsITimer.h" michael@0: #include "nsXULAppAPI.h" michael@0: #include "mozilla/EventForwards.h" michael@0: #include "mozilla/layers/LayersTypes.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "mozilla/TimeStamp.h" michael@0: #include "Units.h" michael@0: michael@0: // forward declarations michael@0: class nsFontMetrics; michael@0: class nsRenderingContext; michael@0: class nsDeviceContext; michael@0: struct nsFont; michael@0: class nsIRollupListener; michael@0: class imgIContainer; michael@0: class gfxASurface; michael@0: class nsIContent; michael@0: class ViewWrapper; michael@0: class nsIWidgetListener; michael@0: class nsIntRegion; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class TabChild; michael@0: } michael@0: namespace layers { michael@0: class Composer2D; michael@0: class CompositorChild; michael@0: class LayerManager; michael@0: class LayerManagerComposite; michael@0: class PLayerTransactionChild; michael@0: } michael@0: namespace gfx { michael@0: class DrawTarget; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Callback function that processes events. michael@0: * michael@0: * The argument is actually a subtype (subclass) of WidgetEvent which carries michael@0: * platform specific information about the event. Platform specific code michael@0: * knows how to deal with it. michael@0: * michael@0: * The return value determines whether or not the default action should take michael@0: * place. michael@0: */ michael@0: typedef nsEventStatus (* EVENT_CALLBACK)(mozilla::WidgetGUIEvent* aEvent); michael@0: michael@0: // Hide the native window system's real window type so as to avoid michael@0: // including native window system types and APIs. This is necessary michael@0: // to ensure cross-platform code. michael@0: typedef void* nsNativeWidget; michael@0: michael@0: /** michael@0: * Flags for the getNativeData function. michael@0: * See getNativeData() michael@0: */ michael@0: #define NS_NATIVE_WINDOW 0 michael@0: #define NS_NATIVE_GRAPHIC 1 michael@0: #define NS_NATIVE_TMP_WINDOW 2 michael@0: #define NS_NATIVE_WIDGET 3 michael@0: #define NS_NATIVE_DISPLAY 4 michael@0: #define NS_NATIVE_REGION 5 michael@0: #define NS_NATIVE_OFFSETX 6 michael@0: #define NS_NATIVE_OFFSETY 7 michael@0: #define NS_NATIVE_PLUGIN_PORT 8 michael@0: #define NS_NATIVE_SCREEN 9 michael@0: // The toplevel GtkWidget containing this nsIWidget: michael@0: #define NS_NATIVE_SHELLWIDGET 10 michael@0: // Has to match to NPNVnetscapeWindow, and shareable across processes michael@0: // HWND on Windows and XID on X11 michael@0: #define NS_NATIVE_SHAREABLE_WINDOW 11 michael@0: #ifdef XP_MACOSX michael@0: #define NS_NATIVE_PLUGIN_PORT_QD 100 michael@0: #define NS_NATIVE_PLUGIN_PORT_CG 101 michael@0: #endif michael@0: #ifdef XP_WIN michael@0: #define NS_NATIVE_TSF_THREAD_MGR 100 michael@0: #define NS_NATIVE_TSF_CATEGORY_MGR 101 michael@0: #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102 michael@0: #define NS_NATIVE_ICOREWINDOW 103 // winrt specific michael@0: #endif michael@0: michael@0: #define NS_IWIDGET_IID \ michael@0: { 0x87d80888, 0x9917, 0x4bfb, \ michael@0: { 0x81, 0xa9, 0x1c, 0x5e, 0x30, 0x9c, 0x78, 0xb4 } } michael@0: michael@0: /* michael@0: * Window shadow styles michael@0: * Also used for the -moz-window-shadow CSS property michael@0: */ michael@0: michael@0: #define NS_STYLE_WINDOW_SHADOW_NONE 0 michael@0: #define NS_STYLE_WINDOW_SHADOW_DEFAULT 1 michael@0: #define NS_STYLE_WINDOW_SHADOW_MENU 2 michael@0: #define NS_STYLE_WINDOW_SHADOW_TOOLTIP 3 michael@0: #define NS_STYLE_WINDOW_SHADOW_SHEET 4 michael@0: michael@0: /** michael@0: * Transparency modes michael@0: */ michael@0: michael@0: enum nsTransparencyMode { michael@0: eTransparencyOpaque = 0, // Fully opaque michael@0: eTransparencyTransparent, // Parts of the window may be transparent michael@0: eTransparencyGlass, // Transparent parts of the window have Vista AeroGlass effect applied michael@0: eTransparencyBorderlessGlass // As above, but without a border around the opaque areas when there would otherwise be one with eTransparencyGlass michael@0: }; michael@0: michael@0: /** michael@0: * Cursor types. michael@0: */ michael@0: michael@0: enum nsCursor { ///(normal cursor, usually rendered as an arrow) michael@0: eCursor_standard, michael@0: ///(system is busy, usually rendered as a hourglass or watch) michael@0: eCursor_wait, michael@0: ///(Selecting something, usually rendered as an IBeam) michael@0: eCursor_select, michael@0: ///(can hyper-link, usually rendered as a human hand) michael@0: eCursor_hyperlink, michael@0: ///(north/south/west/east edge sizing) michael@0: eCursor_n_resize, michael@0: eCursor_s_resize, michael@0: eCursor_w_resize, michael@0: eCursor_e_resize, michael@0: ///(corner sizing) michael@0: eCursor_nw_resize, michael@0: eCursor_se_resize, michael@0: eCursor_ne_resize, michael@0: eCursor_sw_resize, michael@0: eCursor_crosshair, michael@0: eCursor_move, michael@0: eCursor_help, michael@0: eCursor_copy, // CSS3 michael@0: eCursor_alias, michael@0: eCursor_context_menu, michael@0: eCursor_cell, michael@0: eCursor_grab, michael@0: eCursor_grabbing, michael@0: eCursor_spinning, michael@0: eCursor_zoom_in, michael@0: eCursor_zoom_out, michael@0: eCursor_not_allowed, michael@0: eCursor_col_resize, michael@0: eCursor_row_resize, michael@0: eCursor_no_drop, michael@0: eCursor_vertical_text, michael@0: eCursor_all_scroll, michael@0: eCursor_nesw_resize, michael@0: eCursor_nwse_resize, michael@0: eCursor_ns_resize, michael@0: eCursor_ew_resize, michael@0: eCursor_none, michael@0: // This one better be the last one in this list. michael@0: eCursorCount michael@0: }; michael@0: michael@0: enum nsTopLevelWidgetZPlacement { // for PlaceBehind() michael@0: eZPlacementBottom = 0, // bottom of the window stack michael@0: eZPlacementBelow, // just below another widget michael@0: eZPlacementTop // top of the window stack michael@0: }; michael@0: michael@0: /** michael@0: * Before the OS goes to sleep, this topic is notified. michael@0: */ michael@0: #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification" michael@0: michael@0: /** michael@0: * After the OS wakes up, this topic is notified. michael@0: */ michael@0: #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification" michael@0: michael@0: /** michael@0: * Before the OS suspends the current process, this topic is notified. Some michael@0: * OS will kill processes that are suspended instead of resuming them. michael@0: * For that reason this topic may be useful to safely close down resources. michael@0: */ michael@0: #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification" michael@0: michael@0: /** michael@0: * After the current process resumes from being suspended, this topic is michael@0: * notified. michael@0: */ michael@0: #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification" michael@0: michael@0: /** michael@0: * Preference for receiving IME updates michael@0: * michael@0: * If mWantUpdates is not NOTIFY_NOTHING, nsTextStateManager will observe text michael@0: * change and/or selection change and call nsIWidget::NotifyIME() with michael@0: * NOTIFY_IME_OF_SELECTION_CHANGE and/or NOTIFY_IME_OF_TEXT_CHANGE. michael@0: * Please note that the text change observing cost is very expensive especially michael@0: * on an HTML editor has focus. michael@0: * If the IME implementation on a particular platform doesn't care about michael@0: * NOTIFY_IME_OF_SELECTION_CHANGE and/or NOTIFY_IME_OF_TEXT_CHANGE, michael@0: * they should set mWantUpdates to NOTIFY_NOTHING to avoid the cost. michael@0: * If the IME implementation needs notifications even while our process is michael@0: * deactive, it should also set NOTIFY_DURING_DEACTIVE. michael@0: */ michael@0: struct nsIMEUpdatePreference { michael@0: michael@0: typedef uint8_t Notifications; michael@0: michael@0: enum MOZ_ENUM_TYPE(Notifications) michael@0: { michael@0: NOTIFY_NOTHING = 0, michael@0: NOTIFY_SELECTION_CHANGE = 1 << 0, michael@0: NOTIFY_TEXT_CHANGE = 1 << 1, michael@0: NOTIFY_POSITION_CHANGE = 1 << 2, michael@0: // Following values indicate when widget needs or doesn't need notification. michael@0: NOTIFY_CHANGES_CAUSED_BY_COMPOSITION = 1 << 6, michael@0: // NOTE: NOTIFY_DURING_DEACTIVE isn't supported in environments where two michael@0: // or more compositions are possible. E.g., Mac and Linux (GTK). michael@0: NOTIFY_DURING_DEACTIVE = 1 << 7, michael@0: // Changes are notified in following conditions if the instance is michael@0: // just constructed. If some platforms don't need change notifications michael@0: // in some of following conditions, the platform should remove following michael@0: // flags before returing the instance from nsIWidget::GetUpdatePreference(). michael@0: DEFAULT_CONDITIONS_OF_NOTIFYING_CHANGES = michael@0: NOTIFY_CHANGES_CAUSED_BY_COMPOSITION michael@0: }; michael@0: michael@0: nsIMEUpdatePreference() michael@0: : mWantUpdates(DEFAULT_CONDITIONS_OF_NOTIFYING_CHANGES) michael@0: { michael@0: } michael@0: michael@0: nsIMEUpdatePreference(Notifications aWantUpdates) michael@0: : mWantUpdates(aWantUpdates | DEFAULT_CONDITIONS_OF_NOTIFYING_CHANGES) michael@0: { michael@0: } michael@0: michael@0: void DontNotifyChangesCausedByComposition() michael@0: { michael@0: mWantUpdates &= ~DEFAULT_CONDITIONS_OF_NOTIFYING_CHANGES; michael@0: } michael@0: michael@0: bool WantSelectionChange() const michael@0: { michael@0: return !!(mWantUpdates & NOTIFY_SELECTION_CHANGE); michael@0: } michael@0: michael@0: bool WantTextChange() const michael@0: { michael@0: return !!(mWantUpdates & NOTIFY_TEXT_CHANGE); michael@0: } michael@0: michael@0: bool WantPositionChanged() const michael@0: { michael@0: return !!(mWantUpdates & NOTIFY_POSITION_CHANGE); michael@0: } michael@0: michael@0: bool WantChanges() const michael@0: { michael@0: return WantSelectionChange() || WantTextChange(); michael@0: } michael@0: michael@0: bool WantChangesCausedByComposition() const michael@0: { michael@0: return WantChanges() && michael@0: !!(mWantUpdates & NOTIFY_CHANGES_CAUSED_BY_COMPOSITION); michael@0: } michael@0: michael@0: bool WantDuringDeactive() const michael@0: { michael@0: return !!(mWantUpdates & NOTIFY_DURING_DEACTIVE); michael@0: } michael@0: michael@0: Notifications mWantUpdates; michael@0: }; michael@0: michael@0: michael@0: /* michael@0: * Contains IMEStatus plus information about the current michael@0: * input context that the IME can use as hints if desired. michael@0: */ michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: michael@0: struct IMEState { michael@0: /** michael@0: * IME enabled states, the mEnabled value of michael@0: * SetInputContext()/GetInputContext() should be one value of following michael@0: * values. michael@0: * michael@0: * WARNING: If you change these values, you also need to edit: michael@0: * nsIDOMWindowUtils.idl michael@0: * nsContentUtils::GetWidgetStatusFromIMEStatus michael@0: */ michael@0: enum Enabled { michael@0: /** michael@0: * 'Disabled' means the user cannot use IME. So, the IME open state should michael@0: * be 'closed' during 'disabled'. michael@0: */ michael@0: DISABLED, michael@0: /** michael@0: * 'Enabled' means the user can use IME. michael@0: */ michael@0: ENABLED, michael@0: /** michael@0: * 'Password' state is a special case for the password editors. michael@0: * E.g., on mac, the password editors should disable the non-Roman michael@0: * keyboard layouts at getting focus. Thus, the password editor may have michael@0: * special rules on some platforms. michael@0: */ michael@0: PASSWORD, michael@0: /** michael@0: * This state is used when a plugin is focused. michael@0: * When a plug-in is focused content, we should send native events michael@0: * directly. Because we don't process some native events, but they may michael@0: * be needed by the plug-in. michael@0: */ michael@0: PLUGIN michael@0: }; michael@0: Enabled mEnabled; michael@0: michael@0: /** michael@0: * IME open states the mOpen value of SetInputContext() should be one value of michael@0: * OPEN, CLOSE or DONT_CHANGE_OPEN_STATE. GetInputContext() should return michael@0: * OPEN, CLOSE or OPEN_STATE_NOT_SUPPORTED. michael@0: */ michael@0: enum Open { michael@0: /** michael@0: * 'Unsupported' means the platform cannot return actual IME open state. michael@0: * This value is used only by GetInputContext(). michael@0: */ michael@0: OPEN_STATE_NOT_SUPPORTED, michael@0: /** michael@0: * 'Don't change' means the widget shouldn't change IME open state when michael@0: * SetInputContext() is called. michael@0: */ michael@0: DONT_CHANGE_OPEN_STATE = OPEN_STATE_NOT_SUPPORTED, michael@0: /** michael@0: * 'Open' means that IME should compose in its primary language (or latest michael@0: * input mode except direct ASCII character input mode). Even if IME is michael@0: * opened by this value, users should be able to close IME by theirselves. michael@0: * Web contents can specify this value by |ime-mode: active;|. michael@0: */ michael@0: OPEN, michael@0: /** michael@0: * 'Closed' means that IME shouldn't handle key events (or should handle michael@0: * as ASCII character inputs on mobile device). Even if IME is closed by michael@0: * this value, users should be able to open IME by theirselves. michael@0: * Web contents can specify this value by |ime-mode: inactive;|. michael@0: */ michael@0: CLOSED michael@0: }; michael@0: Open mOpen; michael@0: michael@0: IMEState() : mEnabled(ENABLED), mOpen(DONT_CHANGE_OPEN_STATE) { } michael@0: michael@0: IMEState(Enabled aEnabled, Open aOpen = DONT_CHANGE_OPEN_STATE) : michael@0: mEnabled(aEnabled), mOpen(aOpen) michael@0: { michael@0: } michael@0: }; michael@0: michael@0: struct InputContext { michael@0: InputContext() : mNativeIMEContext(nullptr) {} michael@0: michael@0: bool IsPasswordEditor() const michael@0: { michael@0: return mHTMLInputType.LowerCaseEqualsLiteral("password"); michael@0: } michael@0: michael@0: IMEState mIMEState; michael@0: michael@0: /* The type of the input if the input is a html input field */ michael@0: nsString mHTMLInputType; michael@0: michael@0: /* The type of the inputmode */ michael@0: nsString mHTMLInputInputmode; michael@0: michael@0: /* A hint for the action that is performed when the input is submitted */ michael@0: nsString mActionHint; michael@0: michael@0: /* Native IME context for the widget. This doesn't come from the argument of michael@0: SetInputContext(). If there is only one context in the process, this may michael@0: be nullptr. */ michael@0: void* mNativeIMEContext; michael@0: }; michael@0: michael@0: struct InputContextAction { michael@0: /** michael@0: * mCause indicates what action causes calling nsIWidget::SetInputContext(). michael@0: * It must be one of following values. michael@0: */ michael@0: enum Cause { michael@0: // The cause is unknown but originated from content. Focus might have been michael@0: // changed by content script. michael@0: CAUSE_UNKNOWN, michael@0: // The cause is unknown but originated from chrome. Focus might have been michael@0: // changed by chrome script. michael@0: CAUSE_UNKNOWN_CHROME, michael@0: // The cause is user's keyboard operation. michael@0: CAUSE_KEY, michael@0: // The cause is user's mouse operation. michael@0: CAUSE_MOUSE michael@0: }; michael@0: Cause mCause; michael@0: michael@0: /** michael@0: * mFocusChange indicates what happened for focus. michael@0: */ michael@0: enum FocusChange { michael@0: FOCUS_NOT_CHANGED, michael@0: // A content got focus. michael@0: GOT_FOCUS, michael@0: // Focused content lost focus. michael@0: LOST_FOCUS, michael@0: // Menu got pseudo focus that means focused content isn't changed but michael@0: // keyboard events will be handled by menu. michael@0: MENU_GOT_PSEUDO_FOCUS, michael@0: // Menu lost pseudo focus that means focused content will handle keyboard michael@0: // events. michael@0: MENU_LOST_PSEUDO_FOCUS michael@0: }; michael@0: FocusChange mFocusChange; michael@0: michael@0: bool ContentGotFocusByTrustedCause() const { michael@0: return (mFocusChange == GOT_FOCUS && michael@0: mCause != CAUSE_UNKNOWN); michael@0: } michael@0: michael@0: bool UserMightRequestOpenVKB() const { michael@0: return (mFocusChange == FOCUS_NOT_CHANGED && michael@0: mCause == CAUSE_MOUSE); michael@0: } michael@0: michael@0: InputContextAction() : michael@0: mCause(CAUSE_UNKNOWN), mFocusChange(FOCUS_NOT_CHANGED) michael@0: { michael@0: } michael@0: michael@0: InputContextAction(Cause aCause, michael@0: FocusChange aFocusChange = FOCUS_NOT_CHANGED) : michael@0: mCause(aCause), mFocusChange(aFocusChange) michael@0: { michael@0: } michael@0: }; michael@0: michael@0: /** michael@0: * Size constraints for setting the minimum and maximum size of a widget. michael@0: * Values are in device pixels. michael@0: */ michael@0: struct SizeConstraints { michael@0: SizeConstraints() michael@0: : mMaxSize(NS_MAXSIZE, NS_MAXSIZE) michael@0: { michael@0: } michael@0: michael@0: SizeConstraints(nsIntSize aMinSize, michael@0: nsIntSize aMaxSize) michael@0: : mMinSize(aMinSize), michael@0: mMaxSize(aMaxSize) michael@0: { michael@0: } michael@0: michael@0: nsIntSize mMinSize; michael@0: nsIntSize mMaxSize; michael@0: }; michael@0: michael@0: // IMEMessage is shared by IMEStateManager and TextComposition. michael@0: // Update values in GeckoEditable.java if you make changes here. michael@0: // XXX Negative values are used in Android... michael@0: enum IMEMessage MOZ_ENUM_TYPE(int8_t) michael@0: { michael@0: // XXX We should replace NOTIFY_IME_OF_CURSOR_POS_CHANGED with michael@0: // NOTIFY_IME_OF_SELECTION_CHANGE later. michael@0: NOTIFY_IME_OF_CURSOR_POS_CHANGED, michael@0: // An editable content is getting focus michael@0: NOTIFY_IME_OF_FOCUS, michael@0: // An editable content is losing focus michael@0: NOTIFY_IME_OF_BLUR, michael@0: // Selection in the focused editable content is changed michael@0: NOTIFY_IME_OF_SELECTION_CHANGE, michael@0: // Text in the focused editable content is changed michael@0: NOTIFY_IME_OF_TEXT_CHANGE, michael@0: // Composition string has been updated michael@0: NOTIFY_IME_OF_COMPOSITION_UPDATE, michael@0: // Position or size of focused element may be changed. michael@0: NOTIFY_IME_OF_POSITION_CHANGE, michael@0: // Request to commit current composition to IME michael@0: // (some platforms may not support) michael@0: REQUEST_TO_COMMIT_COMPOSITION, michael@0: // Request to cancel current composition to IME michael@0: // (some platforms may not support) michael@0: REQUEST_TO_CANCEL_COMPOSITION michael@0: }; michael@0: michael@0: struct IMENotification michael@0: { michael@0: IMENotification(IMEMessage aMessage) michael@0: : mMessage(aMessage) michael@0: { michael@0: switch (aMessage) { michael@0: case NOTIFY_IME_OF_SELECTION_CHANGE: michael@0: mSelectionChangeData.mCausedByComposition = false; michael@0: break; michael@0: case NOTIFY_IME_OF_TEXT_CHANGE: michael@0: mTextChangeData.mStartOffset = 0; michael@0: mTextChangeData.mOldEndOffset = 0; michael@0: mTextChangeData.mNewEndOffset = 0; michael@0: mTextChangeData.mCausedByComposition = false; michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: michael@0: IMEMessage mMessage; michael@0: michael@0: union michael@0: { michael@0: // NOTIFY_IME_OF_SELECTION_CHANGE specific data michael@0: struct michael@0: { michael@0: bool mCausedByComposition; michael@0: } mSelectionChangeData; michael@0: michael@0: // NOTIFY_IME_OF_TEXT_CHANGE specific data michael@0: struct michael@0: { michael@0: uint32_t mStartOffset; michael@0: uint32_t mOldEndOffset; michael@0: uint32_t mNewEndOffset; michael@0: michael@0: bool mCausedByComposition; michael@0: michael@0: uint32_t OldLength() const { return mOldEndOffset - mStartOffset; } michael@0: uint32_t NewLength() const { return mNewEndOffset - mStartOffset; } michael@0: int32_t AdditionalLength() const michael@0: { michael@0: return static_cast(mNewEndOffset - mOldEndOffset); michael@0: } michael@0: bool IsInInt32Range() const michael@0: { michael@0: return mStartOffset <= INT32_MAX && michael@0: mOldEndOffset <= INT32_MAX && michael@0: mNewEndOffset <= INT32_MAX; michael@0: } michael@0: } mTextChangeData; michael@0: }; michael@0: michael@0: bool IsCausedByComposition() const michael@0: { michael@0: switch (mMessage) { michael@0: case NOTIFY_IME_OF_SELECTION_CHANGE: michael@0: return mSelectionChangeData.mCausedByComposition; michael@0: case NOTIFY_IME_OF_TEXT_CHANGE: michael@0: return mTextChangeData.mCausedByComposition; michael@0: default: michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: private: michael@0: IMENotification(); michael@0: }; michael@0: michael@0: } // namespace widget michael@0: } // namespace mozilla michael@0: michael@0: /** michael@0: * The base class for all the widgets. It provides the interface for michael@0: * all basic and necessary functionality. michael@0: */ michael@0: class nsIWidget : public nsISupports { michael@0: protected: michael@0: typedef mozilla::dom::TabChild TabChild; michael@0: michael@0: public: michael@0: typedef mozilla::layers::Composer2D Composer2D; michael@0: typedef mozilla::layers::CompositorChild CompositorChild; michael@0: typedef mozilla::layers::LayerManager LayerManager; michael@0: typedef mozilla::layers::LayerManagerComposite LayerManagerComposite; michael@0: typedef mozilla::layers::LayersBackend LayersBackend; michael@0: typedef mozilla::layers::PLayerTransactionChild PLayerTransactionChild; michael@0: typedef mozilla::widget::IMEMessage IMEMessage; michael@0: typedef mozilla::widget::IMENotification IMENotification; michael@0: typedef mozilla::widget::IMEState IMEState; michael@0: typedef mozilla::widget::InputContext InputContext; michael@0: typedef mozilla::widget::InputContextAction InputContextAction; michael@0: typedef mozilla::widget::SizeConstraints SizeConstraints; michael@0: michael@0: // Used in UpdateThemeGeometries. michael@0: struct ThemeGeometry { michael@0: // The -moz-appearance value for the themed widget michael@0: uint8_t mWidgetType; michael@0: // The device-pixel rect within the window for the themed widget michael@0: nsIntRect mRect; michael@0: michael@0: ThemeGeometry(uint8_t aWidgetType, const nsIntRect& aRect) michael@0: : mWidgetType(aWidgetType) michael@0: , mRect(aRect) michael@0: { } michael@0: }; michael@0: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID) michael@0: michael@0: nsIWidget() michael@0: : mLastChild(nullptr) michael@0: , mPrevSibling(nullptr) michael@0: , mOnDestroyCalled(false) michael@0: , mWindowType(eWindowType_child) michael@0: , mZIndex(0) michael@0: michael@0: { michael@0: ClearNativeTouchSequence(); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Create and initialize a widget. michael@0: * michael@0: * All the arguments can be null in which case a top level window michael@0: * with size 0 is created. The event callback function has to be michael@0: * provided only if the caller wants to deal with the events this michael@0: * widget receives. The event callback is basically a preprocess michael@0: * hook called synchronously. The return value determines whether michael@0: * the event goes to the default window procedure or it is hidden michael@0: * to the os. The assumption is that if the event handler returns michael@0: * false the widget does not see the event. The widget should not michael@0: * automatically clear the window to the background color. The michael@0: * calling code must handle paint messages and clear the background michael@0: * itself. michael@0: * michael@0: * In practice at least one of aParent and aNativeParent will be null. If michael@0: * both are null the widget isn't parented (e.g. context menus or michael@0: * independent top level windows). michael@0: * michael@0: * The dimensions given in aRect are specified in the parent's michael@0: * coordinate system, or for parentless widgets such as top-level michael@0: * windows, in global CSS pixels. michael@0: * michael@0: * @param aParent parent nsIWidget michael@0: * @param aNativeParent native parent widget michael@0: * @param aRect the widget dimension michael@0: * @param aContext michael@0: * @param aInitData data that is used for widget initialization michael@0: * michael@0: */ michael@0: NS_IMETHOD Create(nsIWidget *aParent, michael@0: nsNativeWidget aNativeParent, michael@0: const nsIntRect &aRect, michael@0: nsDeviceContext *aContext, michael@0: nsWidgetInitData *aInitData = nullptr) = 0; michael@0: michael@0: /** michael@0: * Allocate, initialize, and return a widget that is a child of michael@0: * |this|. The returned widget (if nonnull) has gone through the michael@0: * equivalent of CreateInstance(widgetCID) + Create(...). michael@0: * michael@0: * |CreateChild()| lets widget backends decide whether to parent michael@0: * the new child widget to this, nonnatively parent it, or both. michael@0: * This interface exists to support the PuppetWidget backend, michael@0: * which is entirely non-native. All other params are the same as michael@0: * for |Create()|. michael@0: * michael@0: * |aForceUseIWidgetParent| forces |CreateChild()| to only use the michael@0: * |nsIWidget*| this, not its native widget (if it exists), when michael@0: * calling |Create()|. This is a timid hack around poorly michael@0: * understood code, and shouldn't be used in new code. michael@0: */ michael@0: virtual already_AddRefed michael@0: CreateChild(const nsIntRect &aRect, michael@0: nsDeviceContext *aContext, michael@0: nsWidgetInitData *aInitData = nullptr, michael@0: bool aForceUseIWidgetParent = false) = 0; michael@0: michael@0: /** michael@0: * Attach to a top level widget. michael@0: * michael@0: * In cases where a top level chrome widget is being used as a content michael@0: * container, attach a secondary listener and update the device michael@0: * context. The primary widget listener will continue to be called for michael@0: * notifications relating to the top-level window, whereas other michael@0: * notifications such as painting and events will instead be called via michael@0: * the attached listener. SetAttachedWidgetListener should be used to michael@0: * assign the attached listener. michael@0: * michael@0: * aUseAttachedEvents if true, events are sent to the attached listener michael@0: * instead of the normal listener. michael@0: * aContext The new device context for the view michael@0: */ michael@0: NS_IMETHOD AttachViewToTopLevel(bool aUseAttachedEvents, michael@0: nsDeviceContext *aContext) = 0; michael@0: michael@0: /** michael@0: * Accessor functions to get and set the attached listener. Used by michael@0: * nsView in connection with AttachViewToTopLevel above. michael@0: */ michael@0: virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0; michael@0: virtual nsIWidgetListener* GetAttachedWidgetListener() = 0; michael@0: michael@0: /** michael@0: * Accessor functions to get and set the listener which handles various michael@0: * actions for the widget. michael@0: */ michael@0: //@{ michael@0: virtual nsIWidgetListener* GetWidgetListener() = 0; michael@0: virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0; michael@0: //@} michael@0: michael@0: /** michael@0: * Close and destroy the internal native window. michael@0: * This method does not delete the widget. michael@0: */ michael@0: michael@0: NS_IMETHOD Destroy(void) = 0; michael@0: michael@0: /** michael@0: * Destroyed() returns true if Destroy() has been called already. michael@0: * Otherwise, false. michael@0: */ michael@0: bool Destroyed() const { return mOnDestroyCalled; } michael@0: michael@0: michael@0: /** michael@0: * Reparent a widget michael@0: * michael@0: * Change the widget's parent. Null parents are allowed. michael@0: * michael@0: * @param aNewParent new parent michael@0: */ michael@0: NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0; michael@0: michael@0: NS_IMETHOD RegisterTouchWindow() = 0; michael@0: NS_IMETHOD UnregisterTouchWindow() = 0; michael@0: michael@0: /** michael@0: * Return the parent Widget of this Widget or nullptr if this is a michael@0: * top level window michael@0: * michael@0: * @return the parent widget or nullptr if it does not have a parent michael@0: * michael@0: */ michael@0: virtual nsIWidget* GetParent(void) = 0; michael@0: michael@0: /** michael@0: * Return the top level Widget of this Widget michael@0: * michael@0: * @return the top level widget michael@0: */ michael@0: virtual nsIWidget* GetTopLevelWidget() = 0; michael@0: michael@0: /** michael@0: * Return the top (non-sheet) parent of this Widget if it's a sheet, michael@0: * or nullptr if this isn't a sheet (or some other error occurred). michael@0: * Sheets are only supported on some platforms (currently only OS X). michael@0: * michael@0: * @return the top (non-sheet) parent widget or nullptr michael@0: * michael@0: */ michael@0: virtual nsIWidget* GetSheetWindowParent(void) = 0; michael@0: michael@0: /** michael@0: * Return the physical DPI of the screen containing the window ... michael@0: * the number of device pixels per inch. michael@0: */ michael@0: virtual float GetDPI() = 0; michael@0: michael@0: /** michael@0: * Return the default scale factor for the window. This is the michael@0: * default number of device pixels per CSS pixel to use. This should michael@0: * depend on OS/platform settings such as the Mac's "UI scale factor" michael@0: * or Windows' "font DPI". This will take into account Gecko preferences michael@0: * overriding the system setting. michael@0: */ michael@0: mozilla::CSSToLayoutDeviceScale GetDefaultScale(); michael@0: michael@0: /** michael@0: * Return the Gecko override of the system default scale, if any; michael@0: * returns <= 0.0 if the system scale should be used as-is. michael@0: * nsIWidget::GetDefaultScale() [above] takes this into account. michael@0: * It is exposed here so that code that wants to check for a michael@0: * default-scale override without having a widget on hand can michael@0: * easily access the same value. michael@0: * Note that any scale override is a browser-wide value, whereas michael@0: * the default GetDefaultScale value (when no override is present) michael@0: * may vary between widgets (or screens). michael@0: */ michael@0: static double DefaultScaleOverride(); michael@0: michael@0: /** michael@0: * Return the first child of this widget. Will return null if michael@0: * there are no children. michael@0: */ michael@0: nsIWidget* GetFirstChild() const { michael@0: return mFirstChild; michael@0: } michael@0: michael@0: /** michael@0: * Return the last child of this widget. Will return null if michael@0: * there are no children. michael@0: */ michael@0: nsIWidget* GetLastChild() const { michael@0: return mLastChild; michael@0: } michael@0: michael@0: /** michael@0: * Return the next sibling of this widget michael@0: */ michael@0: nsIWidget* GetNextSibling() const { michael@0: return mNextSibling; michael@0: } michael@0: michael@0: /** michael@0: * Set the next sibling of this widget michael@0: */ michael@0: void SetNextSibling(nsIWidget* aSibling) { michael@0: mNextSibling = aSibling; michael@0: } michael@0: michael@0: /** michael@0: * Return the previous sibling of this widget michael@0: */ michael@0: nsIWidget* GetPrevSibling() const { michael@0: return mPrevSibling; michael@0: } michael@0: michael@0: /** michael@0: * Set the previous sibling of this widget michael@0: */ michael@0: void SetPrevSibling(nsIWidget* aSibling) { michael@0: mPrevSibling = aSibling; michael@0: } michael@0: michael@0: /** michael@0: * Show or hide this widget michael@0: * michael@0: * @param aState true to show the Widget, false to hide it michael@0: * michael@0: */ michael@0: NS_IMETHOD Show(bool aState) = 0; michael@0: michael@0: /** michael@0: * Make the window modal michael@0: * michael@0: */ michael@0: NS_IMETHOD SetModal(bool aModal) = 0; michael@0: michael@0: /** michael@0: * The maximum number of simultaneous touch contacts supported by the device. michael@0: * In the case of devices with multiple digitizers (e.g. multiple touch screens), michael@0: * the value will be the maximum of the set of maximum supported contacts by michael@0: * each individual digitizer. michael@0: */ michael@0: virtual uint32_t GetMaxTouchPoints() const = 0; michael@0: michael@0: /** michael@0: * Returns whether the window is visible michael@0: * michael@0: */ michael@0: virtual bool IsVisible() const = 0; michael@0: michael@0: /** michael@0: * Perform platform-dependent sanity check on a potential window position. michael@0: * This is guaranteed to work only for top-level windows. michael@0: * michael@0: * @param aAllowSlop: if true, allow the window to slop offscreen; michael@0: * the window should be partially visible. if false, michael@0: * force the entire window onscreen (or at least michael@0: * the upper-left corner, if it's too large). michael@0: * @param aX in: an x position expressed in screen coordinates. michael@0: * out: the x position constrained to fit on the screen(s). michael@0: * @param aY in: an y position expressed in screen coordinates. michael@0: * out: the y position constrained to fit on the screen(s). michael@0: * @return vapid success indication. but see also the parameters. michael@0: * michael@0: **/ michael@0: NS_IMETHOD ConstrainPosition(bool aAllowSlop, michael@0: int32_t *aX, michael@0: int32_t *aY) = 0; michael@0: michael@0: /** michael@0: * NOTE: michael@0: * michael@0: * For a top-level window widget, the "parent's coordinate system" is the michael@0: * "global" display pixel coordinate space, *not* device pixels (which michael@0: * may be inconsistent between multiple screens, at least in the Mac OS michael@0: * case with mixed hi-dpi and lo-dpi displays). This applies to all the michael@0: * following Move and Resize widget APIs. michael@0: * michael@0: * The display-/device-pixel distinction becomes important for (at least) michael@0: * Mac OS X with Hi-DPI (retina) displays, and Windows when the UI scale michael@0: * factor is set to other than 100%. michael@0: * michael@0: * The Move and Resize methods take floating-point parameters, rather than michael@0: * integer ones. This is important when manipulating top-level widgets, michael@0: * where the coordinate system may not be an integral multiple of the michael@0: * device-pixel space. michael@0: **/ michael@0: michael@0: /** michael@0: * Move this widget. michael@0: * michael@0: * Coordinates refer to the top-left of the widget. For toplevel windows michael@0: * with decorations, this is the top-left of the titlebar and frame . michael@0: * michael@0: * @param aX the new x position expressed in the parent's coordinate system michael@0: * @param aY the new y position expressed in the parent's coordinate system michael@0: * michael@0: **/ michael@0: NS_IMETHOD Move(double aX, double aY) = 0; michael@0: michael@0: /** michael@0: * Reposition this widget so that the client area has the given offset. michael@0: * michael@0: * @param aX the new x offset of the client area expressed as an michael@0: * offset from the origin of the client area of the parent michael@0: * widget (for root widgets and popup widgets it is in michael@0: * screen coordinates) michael@0: * @param aY the new y offset of the client area expressed as an michael@0: * offset from the origin of the client area of the parent michael@0: * widget (for root widgets and popup widgets it is in michael@0: * screen coordinates) michael@0: * michael@0: **/ michael@0: NS_IMETHOD MoveClient(double aX, double aY) = 0; michael@0: michael@0: /** michael@0: * Resize this widget. Any size constraints set for the window by a michael@0: * previous call to SetSizeConstraints will be applied. michael@0: * michael@0: * @param aWidth the new width expressed in the parent's coordinate system michael@0: * @param aHeight the new height expressed in the parent's coordinate system michael@0: * @param aRepaint whether the widget should be repainted michael@0: * michael@0: */ michael@0: NS_IMETHOD Resize(double aWidth, michael@0: double aHeight, michael@0: bool aRepaint) = 0; michael@0: michael@0: /** michael@0: * Move or resize this widget. Any size constraints set for the window by michael@0: * a previous call to SetSizeConstraints will be applied. michael@0: * michael@0: * @param aX the new x position expressed in the parent's coordinate system michael@0: * @param aY the new y position expressed in the parent's coordinate system michael@0: * @param aWidth the new width expressed in the parent's coordinate system michael@0: * @param aHeight the new height expressed in the parent's coordinate system michael@0: * @param aRepaint whether the widget should be repainted if the size changes michael@0: * michael@0: */ michael@0: NS_IMETHOD Resize(double aX, michael@0: double aY, michael@0: double aWidth, michael@0: double aHeight, michael@0: bool aRepaint) = 0; michael@0: michael@0: /** michael@0: * Resize the widget so that the inner client area has the given size. michael@0: * michael@0: * @param aWidth the new width of the client area. michael@0: * @param aHeight the new height of the client area. michael@0: * @param aRepaint whether the widget should be repainted michael@0: * michael@0: */ michael@0: NS_IMETHOD ResizeClient(double aWidth, michael@0: double aHeight, michael@0: bool aRepaint) = 0; michael@0: michael@0: /** michael@0: * Resize and reposition the widget so tht inner client area has the given michael@0: * offset and size. michael@0: * michael@0: * @param aX the new x offset of the client area expressed as an michael@0: * offset from the origin of the client area of the parent michael@0: * widget (for root widgets and popup widgets it is in michael@0: * screen coordinates) michael@0: * @param aY the new y offset of the client area expressed as an michael@0: * offset from the origin of the client area of the parent michael@0: * widget (for root widgets and popup widgets it is in michael@0: * screen coordinates) michael@0: * @param aWidth the new width of the client area. michael@0: * @param aHeight the new height of the client area. michael@0: * @param aRepaint whether the widget should be repainted michael@0: * michael@0: */ michael@0: NS_IMETHOD ResizeClient(double aX, michael@0: double aY, michael@0: double aWidth, michael@0: double aHeight, michael@0: bool aRepaint) = 0; michael@0: michael@0: /** michael@0: * Sets the widget's z-index. michael@0: */ michael@0: virtual void SetZIndex(int32_t aZIndex) = 0; michael@0: michael@0: /** michael@0: * Gets the widget's z-index. michael@0: */ michael@0: int32_t GetZIndex() michael@0: { michael@0: return mZIndex; michael@0: } michael@0: michael@0: /** michael@0: * Position this widget just behind the given widget. (Used to michael@0: * control z-order for top-level widgets. Get/SetZIndex by contrast michael@0: * control z-order for child widgets of other widgets.) michael@0: * @param aPlacement top, bottom, or below a widget michael@0: * (if top or bottom, param aWidget is ignored) michael@0: * @param aWidget widget to place this widget behind michael@0: * (only if aPlacement is eZPlacementBelow). michael@0: * null is equivalent to aPlacement of eZPlacementTop michael@0: * @param aActivate true to activate the widget after placing it michael@0: */ michael@0: NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, michael@0: nsIWidget *aWidget, bool aActivate) = 0; michael@0: michael@0: /** michael@0: * Minimize, maximize or normalize the window size. michael@0: * Takes a value from nsSizeMode (see nsIWidgetListener.h) michael@0: */ michael@0: NS_IMETHOD SetSizeMode(int32_t aMode) = 0; michael@0: michael@0: /** michael@0: * Return size mode (minimized, maximized, normalized). michael@0: * Returns a value from nsSizeMode (see nsIWidgetListener.h) michael@0: */ michael@0: virtual int32_t SizeMode() = 0; michael@0: michael@0: /** michael@0: * Enable or disable this Widget michael@0: * michael@0: * @param aState true to enable the Widget, false to disable it. michael@0: * michael@0: */ michael@0: NS_IMETHOD Enable(bool aState) = 0; michael@0: michael@0: /** michael@0: * Ask whether the widget is enabled michael@0: */ michael@0: virtual bool IsEnabled() const = 0; michael@0: michael@0: /** michael@0: * Request activation of this window or give focus to this widget. michael@0: * michael@0: * @param aRaise If true, this function requests activation of this michael@0: * widget's toplevel window. michael@0: * If false, the appropriate toplevel window (which in michael@0: * the case of popups may not be this widget's toplevel michael@0: * window) is already active. michael@0: */ michael@0: NS_IMETHOD SetFocus(bool aRaise = false) = 0; michael@0: michael@0: /** michael@0: * Get this widget's outside dimensions relative to its parent widget. For michael@0: * popup widgets the returned rect is in screen coordinates and not michael@0: * relative to its parent widget. michael@0: * michael@0: * @param aRect On return it holds the x, y, width and height of michael@0: * this widget. michael@0: */ michael@0: NS_IMETHOD GetBounds(nsIntRect &aRect) = 0; michael@0: michael@0: /** michael@0: * Get this widget's outside dimensions in global coordinates. This michael@0: * includes any title bar on the window. michael@0: * michael@0: * @param aRect On return it holds the x, y, width and height of michael@0: * this widget. michael@0: */ michael@0: NS_IMETHOD GetScreenBounds(nsIntRect &aRect) = 0; michael@0: michael@0: /** michael@0: * Get this widget's client area bounds, if the window has a 3D border michael@0: * appearance this returns the area inside the border. The position is the michael@0: * position of the client area relative to the client area of the parent michael@0: * widget (for root widgets and popup widgets it is in screen coordinates). michael@0: * michael@0: * @param aRect On return it holds the x. y, width and height of michael@0: * the client area of this widget. michael@0: */ michael@0: NS_IMETHOD GetClientBounds(nsIntRect &aRect) = 0; michael@0: michael@0: /** michael@0: * Get the non-client area dimensions of the window. michael@0: * michael@0: */ michael@0: NS_IMETHOD GetNonClientMargins(nsIntMargin &margins) = 0; michael@0: michael@0: /** michael@0: * Sets the non-client area dimensions of the window. Pass -1 to restore michael@0: * the system default frame size for that border. Pass zero to remove michael@0: * a border, or pass a specific value adjust a border. Units are in michael@0: * pixels. (DPI dependent) michael@0: * michael@0: * Platform notes: michael@0: * Windows: shrinking top non-client height will remove application michael@0: * icon and window title text. Glass desktops will refuse to set michael@0: * dimensions between zero and size < system default. michael@0: * michael@0: */ michael@0: NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) = 0; michael@0: michael@0: /** michael@0: * Get the client offset from the window origin. michael@0: * michael@0: * @return the x and y of the offset. michael@0: * michael@0: */ michael@0: virtual nsIntPoint GetClientOffset() = 0; michael@0: michael@0: /** michael@0: * Set the background color for this widget michael@0: * michael@0: * @param aColor the new background color michael@0: * michael@0: */ michael@0: michael@0: virtual void SetBackgroundColor(const nscolor &aColor) { } michael@0: michael@0: /** michael@0: * Get the cursor for this widget. michael@0: * michael@0: * @return this widget's cursor. michael@0: */ michael@0: michael@0: virtual nsCursor GetCursor(void) = 0; michael@0: michael@0: /** michael@0: * Set the cursor for this widget michael@0: * michael@0: * @param aCursor the new cursor for this widget michael@0: */ michael@0: michael@0: NS_IMETHOD SetCursor(nsCursor aCursor) = 0; michael@0: michael@0: /** michael@0: * Sets an image as the cursor for this widget. michael@0: * michael@0: * @param aCursor the cursor to set michael@0: * @param aX the X coordinate of the hotspot (from left). michael@0: * @param aY the Y coordinate of the hotspot (from top). michael@0: * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not michael@0: * supported michael@0: */ michael@0: NS_IMETHOD SetCursor(imgIContainer* aCursor, michael@0: uint32_t aHotspotX, uint32_t aHotspotY) = 0; michael@0: michael@0: /** michael@0: * Get the window type of this widget. michael@0: */ michael@0: nsWindowType WindowType() { return mWindowType; } michael@0: michael@0: /** michael@0: * Set the transparency mode of the top-level window containing this widget. michael@0: * So, e.g., if you call this on the widget for an IFRAME, the top level michael@0: * browser window containing the IFRAME actually gets set. Be careful. michael@0: * michael@0: * This can fail if the platform doesn't support michael@0: * transparency/glass. By default widgets are not michael@0: * transparent. This will also fail if the toplevel window is not michael@0: * a Mozilla window, e.g., if the widget is in an embedded michael@0: * context. michael@0: * michael@0: * After transparency/glass has been enabled, the initial alpha channel michael@0: * value for all pixels is 1, i.e., opaque. michael@0: * If the window is resized then the alpha channel values for michael@0: * all pixels are reset to 1. michael@0: * Pixel RGB color values are already premultiplied with alpha channel values. michael@0: */ michael@0: virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0; michael@0: michael@0: /** michael@0: * Get the transparency mode of the top-level window that contains this michael@0: * widget. michael@0: */ michael@0: virtual nsTransparencyMode GetTransparencyMode() = 0; michael@0: michael@0: /** michael@0: * This represents a command to set the bounds and clip region of michael@0: * a child widget. michael@0: */ michael@0: struct Configuration { michael@0: nsIWidget* mChild; michael@0: nsIntRect mBounds; michael@0: nsTArray mClipRegion; michael@0: }; michael@0: michael@0: /** michael@0: * Sets the clip region of each mChild (which must actually be a child michael@0: * of this widget) to the union of the pixel rects given in michael@0: * mClipRegion, all relative to the top-left of the child michael@0: * widget. Clip regions are not implemented on all platforms and only michael@0: * need to actually work for children that are plugins. michael@0: * michael@0: * Also sets the bounds of each child to mBounds. michael@0: * michael@0: * This will invalidate areas of the children that have changed, but michael@0: * does not need to invalidate any part of this widget. michael@0: * michael@0: * Children should be moved in the order given; the array is michael@0: * sorted so to minimize unnecessary invalidation if children are michael@0: * moved in that order. michael@0: */ michael@0: virtual nsresult ConfigureChildren(const nsTArray& aConfigurations) = 0; michael@0: michael@0: /** michael@0: * Appends to aRects the rectangles constituting this widget's clip michael@0: * region. If this widget is not clipped, appends a single rectangle michael@0: * (0, 0, bounds.width, bounds.height). michael@0: */ michael@0: virtual void GetWindowClipRegion(nsTArray* aRects) = 0; michael@0: michael@0: /** michael@0: * Set the shadow style of the window. michael@0: * michael@0: * Ignored on child widgets and on non-Mac platforms. michael@0: */ michael@0: NS_IMETHOD SetWindowShadowStyle(int32_t aStyle) = 0; michael@0: michael@0: /* michael@0: * On Mac OS X, this method shows or hides the pill button in the titlebar michael@0: * that's used to collapse the toolbar. michael@0: * michael@0: * Ignored on child widgets and on non-Mac platforms. michael@0: */ michael@0: virtual void SetShowsToolbarButton(bool aShow) = 0; michael@0: michael@0: /* michael@0: * On Mac OS X Lion, this method shows or hides the full screen button in michael@0: * the titlebar that handles native full screen mode. michael@0: * michael@0: * Ignored on child widgets, non-Mac platforms, & pre-Lion Mac. michael@0: */ michael@0: virtual void SetShowsFullScreenButton(bool aShow) = 0; michael@0: michael@0: enum WindowAnimationType { michael@0: eGenericWindowAnimation, michael@0: eDocumentWindowAnimation michael@0: }; michael@0: michael@0: /** michael@0: * Sets the kind of top-level window animation this widget should have. On michael@0: * Mac OS X, this causes a particular kind of animation to be shown when the michael@0: * window is first made visible. michael@0: * michael@0: * Ignored on child widgets and on non-Mac platforms. michael@0: */ michael@0: virtual void SetWindowAnimationType(WindowAnimationType aType) = 0; michael@0: michael@0: /** michael@0: * Specifies whether the window title should be drawn even if the window michael@0: * contents extend into the titlebar. Ignored on windows that don't draw michael@0: * in the titlebar. Only implemented on OS X. michael@0: */ michael@0: virtual void SetDrawsTitle(bool aDrawTitle) {} michael@0: michael@0: /** michael@0: * Hide window chrome (borders, buttons) for this widget. michael@0: * michael@0: */ michael@0: NS_IMETHOD HideWindowChrome(bool aShouldHide) = 0; michael@0: michael@0: /** michael@0: * Put the toplevel window into or out of fullscreen mode. michael@0: * michael@0: */ michael@0: NS_IMETHOD MakeFullScreen(bool aFullScreen) = 0; michael@0: michael@0: /** michael@0: * Invalidate a specified rect for a widget so that it will be repainted michael@0: * later. michael@0: */ michael@0: NS_IMETHOD Invalidate(const nsIntRect & aRect) = 0; michael@0: michael@0: enum LayerManagerPersistence michael@0: { michael@0: LAYER_MANAGER_CURRENT = 0, michael@0: LAYER_MANAGER_PERSISTENT michael@0: }; michael@0: michael@0: /** michael@0: * Return the widget's LayerManager. The layer tree for that michael@0: * LayerManager is what gets rendered to the widget. michael@0: * michael@0: * @param aAllowRetaining an outparam that states whether the returned michael@0: * layer manager should be used for retained layers michael@0: */ michael@0: inline LayerManager* GetLayerManager(bool* aAllowRetaining = nullptr) michael@0: { michael@0: return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE, michael@0: LAYER_MANAGER_CURRENT, aAllowRetaining); michael@0: } michael@0: michael@0: inline LayerManager* GetLayerManager(LayerManagerPersistence aPersistence, michael@0: bool* aAllowRetaining = nullptr) michael@0: { michael@0: return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE, michael@0: aPersistence, aAllowRetaining); michael@0: } michael@0: michael@0: /** michael@0: * Like GetLayerManager(), but prefers creating a layer manager of michael@0: * type |aBackendHint| instead of what would normally be created. michael@0: * LayersBackend::LAYERS_NONE means "no hint". michael@0: */ michael@0: virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager, michael@0: LayersBackend aBackendHint, michael@0: LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT, michael@0: bool* aAllowRetaining = nullptr) = 0; michael@0: michael@0: /** michael@0: * Called before each layer manager transaction to allow any preparation michael@0: * for DrawWindowUnderlay/Overlay that needs to be on the main thread. michael@0: * michael@0: * Always called on the main thread. michael@0: */ michael@0: virtual void PrepareWindowEffects() = 0; michael@0: michael@0: /** michael@0: * Called when shutting down the LayerManager to clean-up any cached resources. michael@0: * michael@0: * Always called from the compositing thread, which may be the main-thread if michael@0: * OMTC is not enabled. michael@0: */ michael@0: virtual void CleanupWindowEffects() = 0; michael@0: michael@0: /** michael@0: * Called before rendering using OMTC. Returns false when the widget is michael@0: * not ready to be rendered (for example while the window is closed). michael@0: * michael@0: * Always called from the compositing thread, which may be the main-thread if michael@0: * OMTC is not enabled. michael@0: */ michael@0: virtual bool PreRender(LayerManagerComposite* aManager) = 0; michael@0: michael@0: /** michael@0: * Called after rendering using OMTC. Not called when rendering was michael@0: * cancelled by a negative return value from PreRender. michael@0: * michael@0: * Always called from the compositing thread, which may be the main-thread if michael@0: * OMTC is not enabled. michael@0: */ michael@0: virtual void PostRender(LayerManagerComposite* aManager) = 0; michael@0: michael@0: /** michael@0: * Called before the LayerManager draws the layer tree. michael@0: * michael@0: * Always called from the compositing thread. michael@0: */ michael@0: virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, nsIntRect aRect) = 0; michael@0: michael@0: /** michael@0: * Called after the LayerManager draws the layer tree michael@0: * michael@0: * Always called from the compositing thread. michael@0: */ michael@0: virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect) = 0; michael@0: michael@0: /** michael@0: * Return a DrawTarget for the window which can be composited into. michael@0: * michael@0: * Called by BasicCompositor on the compositor thread for OMTC drawing michael@0: * before each composition. michael@0: */ michael@0: virtual mozilla::TemporaryRef StartRemoteDrawing() = 0; michael@0: michael@0: /** michael@0: * Ensure that what was painted into the DrawTarget returned from michael@0: * StartRemoteDrawing reaches the screen. michael@0: * michael@0: * Called by BasicCompositor on the compositor thread for OMTC drawing michael@0: * after each composition. michael@0: */ michael@0: virtual void EndRemoteDrawing() = 0; michael@0: michael@0: /** michael@0: * Clean up any resources used by Start/EndRemoteDrawing. michael@0: * michael@0: * Called by BasicCompositor on the compositor thread for OMTC drawing michael@0: * when the compositor is destroyed. michael@0: */ michael@0: virtual void CleanupRemoteDrawing() = 0; michael@0: michael@0: /** michael@0: * Called when Gecko knows which themed widgets exist in this window. michael@0: * The passed array contains an entry for every themed widget of the right michael@0: * type (currently only NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR and michael@0: * NS_THEME_TOOLBAR) within the window, except for themed widgets which are michael@0: * transformed or have effects applied to them (e.g. CSS opacity or michael@0: * filters). michael@0: * This could sometimes be called during display list construction michael@0: * outside of painting. michael@0: * If called during painting, it will be called before we actually michael@0: * paint anything. michael@0: */ michael@0: virtual void UpdateThemeGeometries(const nsTArray& aThemeGeometries) = 0; michael@0: michael@0: /** michael@0: * Informs the widget about the region of the window that is opaque. michael@0: * michael@0: * @param aOpaqueRegion the region of the window that is opaque. michael@0: */ michael@0: virtual void UpdateOpaqueRegion(const nsIntRegion &aOpaqueRegion) {} michael@0: michael@0: /** michael@0: * Internal methods michael@0: */ michael@0: michael@0: //@{ michael@0: virtual void AddChild(nsIWidget* aChild) = 0; michael@0: virtual void RemoveChild(nsIWidget* aChild) = 0; michael@0: virtual void* GetNativeData(uint32_t aDataType) = 0; michael@0: virtual void FreeNativeData(void * data, uint32_t aDataType) = 0;//~~~ michael@0: michael@0: // GetDeviceContext returns a weak pointer to this widget's device context michael@0: virtual nsDeviceContext* GetDeviceContext() = 0; michael@0: michael@0: //@} michael@0: michael@0: /** michael@0: * Set the widget's title. michael@0: * Must be called after Create. michael@0: * michael@0: * @param aTitle string displayed as the title of the widget michael@0: */ michael@0: michael@0: NS_IMETHOD SetTitle(const nsAString& aTitle) = 0; michael@0: michael@0: /** michael@0: * Set the widget's icon. michael@0: * Must be called after Create. michael@0: * michael@0: * @param anIconSpec string specifying the icon to use; convention is to pass michael@0: * a resource: URL from which a platform-dependent resource michael@0: * file name will be constructed michael@0: */ michael@0: michael@0: NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0; michael@0: michael@0: /** michael@0: * Return this widget's origin in screen coordinates. michael@0: * michael@0: * @return screen coordinates stored in the x,y members michael@0: */ michael@0: michael@0: virtual nsIntPoint WidgetToScreenOffset() = 0; michael@0: michael@0: /** michael@0: * Given the specified client size, return the corresponding window size, michael@0: * which includes the area for the borders and titlebar. This method michael@0: * should work even when the window is not yet visible. michael@0: */ michael@0: virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize) = 0; michael@0: michael@0: /** michael@0: * Dispatches an event to the widget michael@0: * michael@0: */ michael@0: NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* event, michael@0: nsEventStatus & aStatus) = 0; michael@0: michael@0: /** michael@0: * Enables the dropping of files to a widget (XXX this is temporary) michael@0: * michael@0: */ michael@0: NS_IMETHOD EnableDragDrop(bool aEnable) = 0; michael@0: michael@0: /** michael@0: * Enables/Disables system mouse capture. michael@0: * @param aCapture true enables mouse capture, false disables mouse capture michael@0: * michael@0: */ michael@0: NS_IMETHOD CaptureMouse(bool aCapture) = 0; michael@0: michael@0: /** michael@0: * Classify the window for the window manager. Mostly for X11. michael@0: */ michael@0: NS_IMETHOD SetWindowClass(const nsAString& xulWinType) = 0; michael@0: michael@0: /** michael@0: * Enables/Disables system capture of any and all events that would cause a michael@0: * popup to be rolled up. aListener should be set to a non-null value for michael@0: * any popups that are not managed by the popup manager. michael@0: * @param aDoCapture true enables capture, false disables capture michael@0: * michael@0: */ michael@0: NS_IMETHOD CaptureRollupEvents(nsIRollupListener* aListener, bool aDoCapture) = 0; michael@0: michael@0: /** michael@0: * Bring this window to the user's attention. This is intended to be a more michael@0: * gentle notification than popping the window to the top or putting up an michael@0: * alert. See, for example, Win32 FlashWindow or the NotificationManager on michael@0: * the Mac. The notification should be suppressed if the window is already michael@0: * in the foreground and should be dismissed when the user brings this window michael@0: * to the foreground. michael@0: * @param aCycleCount Maximum number of times to animate the window per system michael@0: * conventions. If set to -1, cycles indefinitely until michael@0: * window is brought into the foreground. michael@0: */ michael@0: NS_IMETHOD GetAttention(int32_t aCycleCount) = 0; michael@0: michael@0: /** michael@0: * Ask whether there user input events pending. All input events are michael@0: * included, including those not targeted at this nsIwidget instance. michael@0: */ michael@0: virtual bool HasPendingInputEvent() = 0; michael@0: michael@0: /** michael@0: * Set the background color of the window titlebar for this widget. On Mac, michael@0: * for example, this will remove the grey gradient and bottom border and michael@0: * instead show a single, solid color. michael@0: * michael@0: * Ignored on any platform that does not support it. Ignored by widgets that michael@0: * do not represent windows. michael@0: * michael@0: * @param aColor The color to set the title bar background to. Alpha values michael@0: * other than fully transparent (0) are respected if possible michael@0: * on the platform. An alpha of 0 will cause the window to michael@0: * draw with the default style for the platform. michael@0: * michael@0: * @param aActive Whether the color should be applied to active or inactive michael@0: * windows. michael@0: */ michael@0: NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive) = 0; michael@0: michael@0: /** michael@0: * If set to true, the window will draw its contents into the titlebar michael@0: * instead of below it. michael@0: * michael@0: * Ignored on any platform that does not support it. Ignored by widgets that michael@0: * do not represent windows. michael@0: * May result in a resize event, so should only be called from places where michael@0: * reflow and painting is allowed. michael@0: * michael@0: * @param aState Whether drawing into the titlebar should be activated. michael@0: */ michael@0: virtual void SetDrawsInTitlebar(bool aState) = 0; michael@0: michael@0: /* michael@0: * Determine whether the widget shows a resize widget. If it does, michael@0: * aResizerRect returns the resizer's rect. michael@0: * michael@0: * Returns false on any platform that does not support it. michael@0: * michael@0: * @param aResizerRect The resizer's rect in device pixels. michael@0: * @return Whether a resize widget is shown. michael@0: */ michael@0: virtual bool ShowsResizeIndicator(nsIntRect* aResizerRect) = 0; michael@0: michael@0: /** michael@0: * Get the Thebes surface associated with this widget. michael@0: */ michael@0: virtual gfxASurface *GetThebesSurface() = 0; michael@0: michael@0: /** michael@0: * Return the popup that was last rolled up, or null if there isn't one. michael@0: */ michael@0: virtual nsIContent* GetLastRollup() = 0; michael@0: michael@0: /** michael@0: * Begin a window resizing drag, based on the event passed in. michael@0: */ michael@0: NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, michael@0: int32_t aHorizontal, michael@0: int32_t aVertical) = 0; michael@0: michael@0: /** michael@0: * Begin a window moving drag, based on the event passed in. michael@0: */ michael@0: NS_IMETHOD BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) = 0; michael@0: michael@0: enum Modifiers { michael@0: CAPS_LOCK = 0x01, // when CapsLock is active michael@0: NUM_LOCK = 0x02, // when NumLock is active michael@0: SHIFT_L = 0x0100, michael@0: SHIFT_R = 0x0200, michael@0: CTRL_L = 0x0400, michael@0: CTRL_R = 0x0800, michael@0: ALT_L = 0x1000, // includes Option michael@0: ALT_R = 0x2000, michael@0: COMMAND_L = 0x4000, michael@0: COMMAND_R = 0x8000, michael@0: HELP = 0x10000, michael@0: FUNCTION = 0x100000, michael@0: NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad michael@0: }; michael@0: /** michael@0: * Utility method intended for testing. Dispatches native key events michael@0: * to this widget to simulate the press and release of a key. michael@0: * @param aNativeKeyboardLayout a *platform-specific* constant. michael@0: * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource. michael@0: * On Windows, it is converted to a hex string and passed to michael@0: * LoadKeyboardLayout, see michael@0: * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx michael@0: * @param aNativeKeyCode a *platform-specific* keycode. michael@0: * On Windows, this is the virtual key code. michael@0: * @param aModifiers some combination of the above 'Modifiers' flags; michael@0: * not all flags will apply to all platforms. Mac ignores the _R michael@0: * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and michael@0: * FUNCTION. michael@0: * @param aCharacters characters that the OS would decide to generate michael@0: * from the event. On Windows, this is the charCode passed by michael@0: * WM_CHAR. michael@0: * @param aUnmodifiedCharacters characters that the OS would decide michael@0: * to generate from the event if modifier keys (other than shift) michael@0: * were assumed inactive. Needed on Mac, ignored on Windows. michael@0: * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard michael@0: * layout is not supported and the event was not fired michael@0: */ michael@0: virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout, michael@0: int32_t aNativeKeyCode, michael@0: uint32_t aModifierFlags, michael@0: const nsAString& aCharacters, michael@0: const nsAString& aUnmodifiedCharacters) = 0; michael@0: michael@0: /** michael@0: * Utility method intended for testing. Dispatches native mouse events michael@0: * may even move the mouse cursor. On Mac the events are guaranteed to michael@0: * be sent to the window containing this widget, but on Windows they'll go michael@0: * to whatever's topmost on the screen at that position, so for michael@0: * cross-platform testing ensure that your window is at the top of the michael@0: * z-order. michael@0: * @param aPoint screen location of the mouse, in device michael@0: * pixels, with origin at the top left michael@0: * @param aNativeMessage *platform-specific* event type (e.g. on Mac, michael@0: * NSMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN etc) michael@0: * @param aModifierFlags *platform-specific* modifier flags (ignored michael@0: * on Windows) michael@0: */ michael@0: virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, michael@0: uint32_t aNativeMessage, michael@0: uint32_t aModifierFlags) = 0; michael@0: michael@0: /** michael@0: * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native message. michael@0: * aPoint is location in device pixels to which the mouse pointer moves to. michael@0: */ michael@0: virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint) = 0; michael@0: michael@0: /** michael@0: * Utility method intended for testing. Dispatching native mouse scroll michael@0: * events may move the mouse cursor. michael@0: * michael@0: * @param aPoint Mouse cursor position in screen coordinates. michael@0: * In device pixels, the origin at the top left of michael@0: * the primary display. michael@0: * @param aNativeMessage Platform native message. michael@0: * @param aDeltaX The delta value for X direction. If the native michael@0: * message doesn't indicate X direction scrolling, michael@0: * this may be ignored. michael@0: * @param aDeltaY The delta value for Y direction. If the native michael@0: * message doesn't indicate Y direction scrolling, michael@0: * this may be ignored. michael@0: * @param aDeltaZ The delta value for Z direction. If the native michael@0: * message doesn't indicate Z direction scrolling, michael@0: * this may be ignored. michael@0: * @param aModifierFlags Must be values of Modifiers, or zero. michael@0: * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their michael@0: * document. michael@0: */ michael@0: virtual nsresult SynthesizeNativeMouseScrollEvent(nsIntPoint aPoint, michael@0: uint32_t aNativeMessage, michael@0: double aDeltaX, michael@0: double aDeltaY, michael@0: double aDeltaZ, michael@0: uint32_t aModifierFlags, michael@0: uint32_t aAdditionalFlags) = 0; michael@0: michael@0: /* michael@0: * TouchPointerState states for SynthesizeNativeTouchPoint. Match michael@0: * touch states in nsIDOMWindowUtils.idl. michael@0: */ michael@0: enum TouchPointerState { michael@0: // The pointer is in a hover state above the digitizer michael@0: TOUCH_HOVER = 0x01, michael@0: // The pointer is in contact with the digitizer michael@0: TOUCH_CONTACT = 0x02, michael@0: // The pointer has been removed from the digitizer detection area michael@0: TOUCH_REMOVE = 0x04, michael@0: // The pointer has been canceled. Will cancel any pending os level michael@0: // gestures that would triggered as a result of completion of the michael@0: // input sequence. This may not cancel moz platform related events michael@0: // that might get tirggered by input already delivered. michael@0: TOUCH_CANCEL = 0x08 michael@0: }; michael@0: michael@0: /* michael@0: * Create a new or update an existing touch pointer on the digitizer. michael@0: * To trigger os level gestures, individual touch points should michael@0: * transition through a complete set of touch states which should be michael@0: * sent as individual messages. michael@0: * michael@0: * @param aPointerId The touch point id to create or update. michael@0: * @param aPointerState one or more of the touch states listed above michael@0: * @param aScreenX, aScreenY screen coords of this event michael@0: * @param aPressure 0.0 -> 1.0 float val indicating pressure michael@0: * @param aOrientation 0 -> 359 degree value indicating the michael@0: * orientation of the pointer. Use 90 for normal taps. michael@0: */ michael@0: virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId, michael@0: TouchPointerState aPointerState, michael@0: nsIntPoint aPointerScreenPoint, michael@0: double aPointerPressure, michael@0: uint32_t aPointerOrientation) = 0; michael@0: michael@0: /* michael@0: * Cancels all active simulated touch input points and pending long taps. michael@0: * Native widgets should track existing points such that they can clear the michael@0: * digitizer state when this call is made. michael@0: */ michael@0: virtual nsresult ClearNativeTouchSequence(); michael@0: michael@0: /* michael@0: * Helper for simulating a simple tap event with one touch point. When michael@0: * aLongTap is true, simulates a native long tap with a duration equal to michael@0: * ui.click_hold_context_menus.delay. This pref is compatible with the michael@0: * apzc long tap duration. Defaults to 1.5 seconds. michael@0: */ michael@0: nsresult SynthesizeNativeTouchTap(nsIntPoint aPointerScreenPoint, michael@0: bool aLongTap); michael@0: michael@0: private: michael@0: class LongTapInfo michael@0: { michael@0: public: michael@0: LongTapInfo(int32_t aPointerId, nsIntPoint& aPoint, michael@0: mozilla::TimeDuration aDuration) : michael@0: mPointerId(aPointerId), michael@0: mPosition(aPoint), michael@0: mDuration(aDuration), michael@0: mStamp(mozilla::TimeStamp::Now()) michael@0: { michael@0: } michael@0: michael@0: int32_t mPointerId; michael@0: nsIntPoint mPosition; michael@0: mozilla::TimeDuration mDuration; michael@0: mozilla::TimeStamp mStamp; michael@0: }; michael@0: michael@0: static void OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure); michael@0: michael@0: nsAutoPtr mLongTapTouchPoint; michael@0: nsCOMPtr mLongTapTimer; michael@0: static int32_t sPointerIdCounter; michael@0: michael@0: public: michael@0: /** michael@0: * Activates a native menu item at the position specified by the index michael@0: * string. The index string is a string of positive integers separated michael@0: * by the "|" (pipe) character. The last integer in the string represents michael@0: * the item index in a submenu located using the integers preceding it. michael@0: * michael@0: * Example: 1|0|4 michael@0: * In this string, the first integer represents the top-level submenu michael@0: * in the native menu bar. Since the integer is 1, it is the second submeu michael@0: * in the native menu bar. Within that, the first item (index 0) is a michael@0: * submenu, and we want to activate the 5th item within that submenu. michael@0: */ michael@0: virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0; michael@0: michael@0: /** michael@0: * This is used for native menu system testing. michael@0: * michael@0: * Updates a native menu at the position specified by the index string. michael@0: * The index string is a string of positive integers separated by the "|" michael@0: * (pipe) character. michael@0: * michael@0: * Example: 1|0|4 michael@0: * In this string, the first integer represents the top-level submenu michael@0: * in the native menu bar. Since the integer is 1, it is the second submeu michael@0: * in the native menu bar. Within that, the first item (index 0) is a michael@0: * submenu, and we want to update submenu at index 4 within that submenu. michael@0: * michael@0: * If this is called with an empty string it forces a full reload of the michael@0: * menu system. michael@0: */ michael@0: virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0; michael@0: michael@0: /** michael@0: * Notify IME of the specified notification. michael@0: */ michael@0: NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) = 0; michael@0: michael@0: /* michael@0: * Notifies the input context changes. michael@0: */ michael@0: NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, michael@0: const InputContextAction& aAction) = 0; michael@0: michael@0: /* michael@0: * Get current input context. michael@0: */ michael@0: NS_IMETHOD_(InputContext) GetInputContext() = 0; michael@0: michael@0: /* michael@0: * Given a WidgetKeyboardEvent, this method synthesizes a corresponding michael@0: * native (OS-level) event for it. This method allows tests to simulate michael@0: * keystrokes that trigger native key bindings (which require a native michael@0: * event). michael@0: */ michael@0: NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) = 0; michael@0: michael@0: /* michael@0: * Execute native key bindings for aType. michael@0: */ michael@0: typedef void (*DoCommandCallback)(mozilla::Command, void*); michael@0: enum NativeKeyBindingsType michael@0: { michael@0: NativeKeyBindingsForSingleLineEditor, michael@0: NativeKeyBindingsForMultiLineEditor, michael@0: NativeKeyBindingsForRichTextEditor michael@0: }; michael@0: NS_IMETHOD_(bool) ExecuteNativeKeyBinding( michael@0: NativeKeyBindingsType aType, michael@0: const mozilla::WidgetKeyboardEvent& aEvent, michael@0: DoCommandCallback aCallback, michael@0: void* aCallbackData) = 0; michael@0: michael@0: /** michael@0: * Set layers acceleration to 'True' or 'False' michael@0: */ michael@0: NS_IMETHOD SetLayersAcceleration(bool aEnabled) = 0; michael@0: michael@0: /* michael@0: * Get toggled key states. michael@0: * aKeyCode should be NS_VK_CAPS_LOCK or NS_VK_NUM_LOCK or michael@0: * NS_VK_SCROLL_LOCK. michael@0: * aLEDState is the result for current LED state of the key. michael@0: * If the LED is 'ON', it returns TRUE, otherwise, FALSE. michael@0: * If the platform doesn't support the LED state (or we cannot get the michael@0: * state), this method returns NS_ERROR_NOT_IMPLEMENTED. michael@0: */ michael@0: NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState) = 0; michael@0: michael@0: /* michael@0: * Retrieves preference for IME updates michael@0: */ michael@0: virtual nsIMEUpdatePreference GetIMEUpdatePreference() = 0; michael@0: michael@0: /* michael@0: * Call this method when a dialog is opened which has a default button. michael@0: * The button's rectangle should be supplied in aButtonRect. michael@0: */ michael@0: NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) = 0; michael@0: michael@0: /** michael@0: * Compute the overridden system mouse scroll speed on the root content of michael@0: * web pages. The widget may set the same value as aOriginalDelta. E.g., michael@0: * when the system scrolling settings were customized, widget can respect michael@0: * the will of the user. michael@0: * michael@0: * This is called only when the mouse wheel event scrolls the root content michael@0: * of the web pages by line. In other words, this isn't called when the michael@0: * mouse wheel event is used for zoom, page scroll and other special michael@0: * actions. And also this isn't called when the user doesn't use the michael@0: * system wheel speed settings. michael@0: * michael@0: * @param aOriginalDeltaX The X delta value of the current mouse wheel michael@0: * scrolling event. michael@0: * @param aOriginalDeltaX The Y delta value of the current mouse wheel michael@0: * scrolling event. michael@0: * @param aOverriddenDeltaX The overridden mouse scrolling speed along X michael@0: * axis. This value may be same as aOriginalDeltaX. michael@0: * @param aOverriddenDeltaY The overridden mouse scrolling speed along Y michael@0: * axis. This value may be same as aOriginalDeltaY. michael@0: */ michael@0: NS_IMETHOD OverrideSystemMouseScrollSpeed(double aOriginalDeltaX, michael@0: double aOriginalDeltaY, michael@0: double& aOverriddenDeltaX, michael@0: double& aOverriddenDeltaY) = 0; michael@0: michael@0: /** michael@0: * Return true if this process shouldn't use platform widgets, and michael@0: * so should use PuppetWidgets instead. If this returns true, the michael@0: * result of creating and using a platform widget is undefined, michael@0: * and likely to end in crashes or other buggy behavior. michael@0: */ michael@0: static bool michael@0: UsePuppetWidgets() michael@0: { michael@0: return XRE_GetProcessType() == GeckoProcessType_Content; michael@0: } michael@0: michael@0: /** michael@0: * Allocate and return a "puppet widget" that doesn't directly michael@0: * correlate to a platform widget; platform events and data must michael@0: * be fed to it. Currently used in content processes. NULL is michael@0: * returned if puppet widgets aren't supported in this build michael@0: * config, on this platform, or for this process type. michael@0: * michael@0: * This function is called "Create" to match CreateInstance(). michael@0: * The returned widget must still be nsIWidget::Create()d. michael@0: */ michael@0: static already_AddRefed michael@0: CreatePuppetWidget(TabChild* aTabChild); michael@0: michael@0: /** michael@0: * Reparent this widget's native widget. michael@0: * @param aNewParent the native widget of aNewParent is the new native michael@0: * parent widget michael@0: */ michael@0: NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) = 0; michael@0: michael@0: /** michael@0: * Return the internal format of the default framebuffer for this michael@0: * widget. michael@0: */ michael@0: virtual uint32_t GetGLFrameBufferFormat() { return 0; /*GL_NONE*/ } michael@0: michael@0: /** michael@0: * Return true if widget has it's own GL context michael@0: */ michael@0: virtual bool HasGLContext() { return false; } michael@0: michael@0: /** michael@0: * Returns true to indicate that this widget paints an opaque background michael@0: * that we want to be visible under the page, so layout should not force michael@0: * a default background. michael@0: */ michael@0: virtual bool WidgetPaintsBackground() { return false; } michael@0: michael@0: virtual bool NeedsPaint() { michael@0: if (!IsVisible()) { michael@0: return false; michael@0: } michael@0: nsIntRect bounds; michael@0: nsresult rv = GetBounds(bounds); michael@0: NS_ENSURE_SUCCESS(rv, false); michael@0: return !bounds.IsEmpty(); michael@0: } michael@0: michael@0: /** michael@0: * Get the natural bounds of this widget. This method is only michael@0: * meaningful for widgets for which Gecko implements screen michael@0: * rotation natively. When this is the case, GetBounds() returns michael@0: * the widget bounds taking rotation into account, and michael@0: * GetNaturalBounds() returns the bounds *not* taking rotation michael@0: * into account. michael@0: * michael@0: * No code outside of the composition pipeline should know or care michael@0: * about this. If you're not an agent of the compositor, you michael@0: * probably shouldn't call this method. michael@0: */ michael@0: virtual nsIntRect GetNaturalBounds() { michael@0: nsIntRect bounds; michael@0: GetBounds(bounds); michael@0: return bounds; michael@0: } michael@0: michael@0: /** michael@0: * Set size constraints on the window size such that it is never less than michael@0: * the specified minimum size and never larger than the specified maximum michael@0: * size. The size constraints are sizes of the outer rectangle including michael@0: * the window frame and title bar. Use 0 for an unconstrained minimum size michael@0: * and NS_MAXSIZE for an unconstrained maximum size. Note that this method michael@0: * does not necessarily change the size of a window to conform to this size, michael@0: * thus Resize should be called afterwards. michael@0: * michael@0: * @param aConstraints: the size constraints in device pixels michael@0: */ michael@0: virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0; michael@0: michael@0: /** michael@0: * Return the size constraints currently observed by the widget. michael@0: * michael@0: * @return the constraints in device pixels michael@0: */ michael@0: virtual const SizeConstraints& GetSizeConstraints() const = 0; michael@0: michael@0: /** michael@0: * If this is owned by a TabChild, return that. Otherwise return michael@0: * null. michael@0: */ michael@0: virtual TabChild* GetOwningTabChild() { return nullptr; } michael@0: michael@0: /** michael@0: * If this isn't directly compositing to its window surface, michael@0: * return the compositor which is doing that on our behalf. michael@0: */ michael@0: virtual CompositorChild* GetRemoteRenderer() michael@0: { return nullptr; } michael@0: michael@0: /** michael@0: * If this widget has a more efficient composer available for its michael@0: * native framebuffer, return it. michael@0: * michael@0: * This can be called from a non-main thread, but that thread must michael@0: * hold a strong reference to this. michael@0: */ michael@0: virtual Composer2D* GetComposer2D() michael@0: { return nullptr; } michael@0: michael@0: /** michael@0: * Some platforms (only cocoa right now) round widget coordinates to the michael@0: * nearest even pixels (see bug 892994), this function allows us to michael@0: * determine how widget coordinates will be rounded. michael@0: */ michael@0: virtual int32_t RoundsWidgetCoordinatesTo() { return 1; } michael@0: michael@0: protected: michael@0: /** michael@0: * Like GetDefaultScale, but taking into account only the system settings michael@0: * and ignoring Gecko preferences. michael@0: */ michael@0: virtual double GetDefaultScaleInternal() { return 1.0; } michael@0: michael@0: // keep the list of children. We also keep track of our siblings. michael@0: // The ownership model is as follows: parent holds a strong ref to michael@0: // the first element of the list, and each element holds a strong michael@0: // ref to the next element in the list. The prevsibling and michael@0: // lastchild pointers are weak, which is fine as long as they are michael@0: // maintained properly. michael@0: nsCOMPtr mFirstChild; michael@0: nsIWidget* mLastChild; michael@0: nsCOMPtr mNextSibling; michael@0: nsIWidget* mPrevSibling; michael@0: // When Destroy() is called, the sub class should set this true. michael@0: bool mOnDestroyCalled; michael@0: nsWindowType mWindowType; michael@0: int32_t mZIndex; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID) michael@0: michael@0: #endif // nsIWidget_h__