Commit Graph

50 Commits

Author SHA1 Message Date
Carlos Garnacho
a72404dd5a gtk: Mass delete all GtkWidget event mask API
We now rely on toplevels receiving and forwarding all the events
the windowing should be able to handle. Event masks are no longer a
way to determine whether an event is deliverable ot a widget.

Events will always be delivered in the three captured/target/bubbled
phases, widgets can now just attach GtkEventControllers and let those
handle the events.
2017-05-25 16:25:58 +02:00
Matthias Clasen
0e37d67393 text handle: Don't leak adjustments
This can happen if the weak pointer is triggered before the
adjustments are unset. Pointed out in

https://bugzilla.gnome.org/show_bug.cgi?id=774790
2016-11-23 13:57:03 -05:00
Benjamin Otte
1518fe0a8f API: stylecontext: Remove state argument from getters
The argument must always be the current state.
2016-10-16 18:18:58 +02:00
Timm Bäder
9f5baf9130 GtkTextHandle: Use min-width/min-height
instead of GtkWidget's text-handle-width/text-handle-height style
properties
2016-10-16 18:17:21 +02:00
Carlos Garnacho
60d7f4376e GtkTextHandle: Look up for the first child of a scrolled window found
Text handles use to connect to the first GtkScrollable up the hierarchy
so they can be repositioned when scrolling. It makes more sense to look
up the first child of a GtkScrolledWindow, it must be an scrollable too,
and will be the scrollable that can actually change the position of the
text handles.

https://bugzilla.gnome.org/show_bug.cgi?id=761676
2016-02-24 17:58:19 +01:00
Matthias Clasen
ea51db1feb text handle: Port to CSS nodes
Use cursor-handle as the element name for the CSS node that
is used to render text the selection handles.
2015-11-09 23:33:54 -05:00
Carlos Garnacho
4f61fd09c5 texthandle: Request raising of text handle popovers.
https://bugzilla.gnome.org/show_bug.cgi?id=756670
2015-11-03 07:25:33 -05:00
Carlos Garnacho
8147f12eca texthandle: Ensure handles are invalidated on mode changes
Otherwise the "cursor" handle stays with "cursor" appearance instead of
"selection end" when a text selection is started.
2015-10-14 18:44:34 +02:00
Carlos Garnacho
14dde08e33 texthandle: small refactor
These long enums are used too often, shorten things a bit with temp vars.
2015-10-14 18:44:34 +02:00
Carlos Garnacho
cfaa421433 texthandle: Fix Y positioning of text handles
It is assumed that border.top is the same than pointing_to.height (which
equals the strong cursor position), which is not since some time ago.

The border calculation has been move on top too, it is now used in the
Y position one, and doesn't depend on anything we calculate later.
2015-10-14 18:44:34 +02:00
Carlos Garnacho
73bf16b3b0 texthandle: Fix handle dragging on wayland
Text handles are subsurfaces on wayland, so sort of their own toplevel.
This made gtk_widget_translate_coordinates() to bail out there, resulting
in text handles being mispositioned and jumpy. To fix this, translate to
toplevel GtkWindow coordinates manually, and translate coordinates from
there.

Along the way, the coordinates reported in ::handle-dragged have been
fixed so there is no small jumps in either axis (most noticeable in the
X axis when you started dragging, and in the Y axis when moving between
lines of different heights.
2015-10-14 18:44:34 +02:00
Carlos Garnacho
7f57f63eba gtkwindow: Only allow unrestricted positioning to text handle popovers
This behavior has been made optional on add_popover() time, text handles
will keep being able to overflow the window, in order to allow text
selection on views too close to the window edge.

Regular GtkPopovers are reinstaurated to the previous size positioning
logic though, that is, limited by the visible area of the window.
2015-07-06 16:39:06 +02:00
Carlos Garnacho
15bb9acc8a texthandle: Avoid double rendering of background/frame
gtk_render_handle() already renders background/frame itself, avoid
doing this twice.
2015-06-17 15:58:55 +02:00
Carlos Garnacho
76dc8aced5 window: Add concept of popover "parent"
This will be the widget that the popover relates to (::pointing-to in
GtkPopover, ::parent in GtkTextHandle).

Additional API to check the popover/parent relationship between widgets
has been added, which will be useful wherever this is necessary in a
generic manner.

https://bugzilla.gnome.org/show_bug.cgi?id=750993
2015-06-17 15:56:42 +02:00
Ting-Wei Lan
d8657a8156 Fix return value error in _gtk_text_handle_set_direction
https://bugzilla.gnome.org/show_bug.cgi?id=750888
2015-06-13 23:00:21 +08:00
Carlos Garnacho
5a499ef3e1 texthandle: Remove knowledge about window borders
We need to expand beyond these if necessary, so don't artificially
limit things here.
2015-06-11 17:14:23 +02:00
Carlos Garnacho
3a7689bae0 texthandle: Handle ltr/rtl positioning
This setting is per handle, as is dependent on the selected text, rather
than the locale.
2015-06-11 17:14:23 +02:00
Carlos Garnacho
fc6871b43b texthandles: Move start handle to bottom
The asset is going to change to point upwards, so physically place
the handle below the text position.

https://bugzilla.gnome.org/show_bug.cgi?id=750692
2015-06-11 17:12:06 +02:00
Matthias Clasen
ecebdfc58c GtkTextHandle: Improve handle positioning
When we are close the window edge, we need to shrink the 'invisible
border' around the handle to avoid mispositioning it. A fiddly
calculation, but it works.
2015-06-09 21:19:17 -04:00
Matthias Clasen
0b3835a93f GtkTextHandle: position handles properly
Move the handles so that the asymmetric assets align with the
start/end of the selection.
2015-06-09 17:06:27 -04:00
Matthias Clasen
805fa78221 GtkTextHandle: add a drag-started signal
This will be used to discriminate drags from taps.
2015-06-08 06:55:21 -04:00
Carlos Garnacho
1e8be1c446 texthandle: Set prelight state on the pointer-interacted handle
This will be useful with the theming changes to come.

https://bugzilla.gnome.org/show_bug.cgi?id=750396
2015-06-05 08:57:43 -04:00
Carlos Garnacho
88d88591d2 texthandle: Allow setting individual states, and separately to handles
Now each handle gets its individual current state, and we can accumulate
more than one state on these.

https://bugzilla.gnome.org/show_bug.cgi?id=750396
2015-06-05 08:57:43 -04:00
Carlos Garnacho
79f8db1c0d texthandle: Use active state when handles are being dragged
The active state flags is set on both handles when this happens.
2014-12-18 21:20:17 +01:00
Carlos Garnacho
e0b9330880 texthandle: Use the handle widget style context for rendering
Using the parent widget context is a leftover of the pre-popover
implementation, which used GdkWindows directly. This will make the context
reflect widget state, at the expense of changing the selector paths
that used to match the handles.
2014-12-18 21:20:17 +01:00
Matthias Clasen
d4e8a501a0 GtkTextHandle: Better draw() implementation
Conceptually, text handles are boxes, whose content is a 'handle',
so draw background, frame and handle. With this, and the previous
commit, the cursor-handle theming in Adwaita now works as intended.
2014-07-13 13:58:16 -04:00
Carlos Garnacho
ca1510177c texthandle: Mind the invisible area when moving the handle
The handle is still centered horizontally, but the extra vertical
space wasn't taken into account, leading to misplacing the dragging
point (and the handle) during motion events.
2014-05-23 19:54:33 +02:00
Carlos Garnacho
2ba89256f4 texthandle: Make a bigger hit area around texthandles
The hit area now extends to all sides around the handle, instead
of just towards where the text is. This makes it easier to grab
handles once shown.
2014-05-23 19:54:32 +02:00
Matthias Clasen
479babf339 GtkTextHandle: Deal with parent_scrollable going away
Use a weak reference to notice when parent_scrollable is
going away.

https://bugzilla.gnome.org/show_bug.cgi?id=724392
2014-02-19 00:24:30 -05:00
Carlos Garnacho
9fe26a93eb texthandle: Update child visibility of handles within scrollables
If the rect a handle points to starts falling outside of the parent
scrollable allocation, the handle will be automatically hidden, and
shown again when the rectangle is visible too.
2014-01-22 17:10:07 +01:00
Carlos Garnacho
328404795b texthandle: Track parent scrollable adjustments
This makes sure texthandles follow the parent if it is contained within a
GtkScrollable.
2014-01-22 17:10:07 +01:00
Carlos Garnacho
360d5f04c0 texthandle: ensure handles are recreated on parent hierarchy changes
This ensures the handles come out right even if the parent widget is
reparented to a different toplevel.
2014-01-22 17:10:07 +01:00
Carlos Garnacho
834ad653ea texthandle: Use GtkWindow private popover API. 2014-01-22 17:10:07 +01:00
Carlos Garnacho
31042fe95f popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.

The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.

This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-22 17:10:06 +01:00
Carlos Garnacho
bd5490ad62 texthandle: Fix arguments in ::style-updated callback 2014-01-22 17:10:06 +01:00
Carlos Garnacho
4a8a2286e1 texthandle: Remove relative_to API
It's unused now, GtkTextHandle uses widget coordinates.
2014-01-22 17:10:05 +01:00
Carlos Garnacho
844c6b8951 texthandles: Use GtkWindow popovers API
This offers the same behavior, but GDK_WINDOW_TEMP windows aren't used
anymore, involving less translations from/to root coordinates, plus no
glitches in having handles snap to content as windows move.
2014-01-22 17:10:05 +01:00
Benjamin Otte
7f0c29bcd7 texthandle: Use the parent widget's style context
... instead of creating our own.
2013-10-05 13:57:51 +02:00
Emmanuele Bassi
0899ef7cc9 gtk: Use new macros for defining private data
https://bugzilla.gnome.org/show_bug.cgi?id=702996
2013-07-09 09:30:02 +01:00
Carlos Garnacho
a97178af65 texthandle: Set a bigger input shape, covering the line height
Now, even if the handles being rendered are small, the handle touch
input shape will be as wide as the visible part of the rendered asset, and
high enough to cover both the handle and the height of the line where
the selection bound is.

Also, make handles have the same virtual distance to the line top/bottom
when a drag starts, so the handle doesn't jump to another line after a
too short threshold.
2013-03-05 16:47:58 -05:00
Carlos Garnacho
d97861bd8b texthandles: Keep state internally to avoid X overhead
Handles now do sync X calls less often. As visibility state
is kept, it now can move+resize+show handles at once instead
of in separated steps.
2013-03-05 16:47:58 -05:00
Alexander Larsson
c6bbfc8e3d Add a few missing gtk_widget_unregister_window calls
This was causing warnings on widget unparent like:

Gdk-CRITICAL **: gdk_window_has_native: assertion `GDK_IS_WINDOW (window)' failed

Becasue the window was not properly removed from the lists on unrealize.
2013-02-18 09:35:58 +01:00
Alexander Larsson
ebb84e8d19 TextHandle: Don't draw handles if not visible
When calling gtk_widget_draw() on the entry gtk_cairo_should_draw_window()
will return TRUE for all windows. This is used when rendering a widget to
somewhere other than the screen, and its now used for transparent widgets.
This caused the texthandle to always draw itself and terminate the draw
handler for the entry.

Instead we now only draw the markers when really visible, plus we return
FALSE to avoid stopping the entry drawing.

https://bugzilla.gnome.org/show_bug.cgi?id=687842
2013-02-07 11:11:38 +01:00
Alexander Larsson
3d4cd4db3e Add gtk_widget_(un)register_window
This replaces the previously hardcoded calls to gdk_window_set_user_data,
and also lets us track which windows are a part of a widget. Old code
should continue working as is, but new features that require the
windows may not work perfectly.

We need this for the transparent widget support to work, as we need
to specially mark the windows of child widgets.

https://bugzilla.gnome.org/show_bug.cgi?id=687842
2013-02-07 11:11:37 +01:00
Carlos Garnacho
63c75a2384 texthandles: Add an extra style class to the cursor-mode handle
Themes may want to render handles differently depending on whether
the widget is in selection mode (2 handles enclosing a selection) or
cursor mode (one handle pointing out the insertion cursor).
2012-10-26 18:38:38 +02:00
Carlos Garnacho
0eb09ac0f2 texthandles: set input shape on handles' window
This improves both interaction and theming, as it allows
arbitrary handle shapes while just being draggable from
the visible areas.

This way themes can set up handles with the hotspot visually
displaced from the horizontal center, as long as the hotspot
lies centered in the image/svg asset.
2012-10-26 18:35:24 +02:00
Carlos Garnacho
f6952ceb82 texthandle: Fix shape setup on non-composited environments
The check on the handle to be drawn on the mask was based on the yet to
be set priv->windows pointers, pass explicitly the handle position to
have the shape correctly initialized on non-composited environments
2012-10-26 17:46:40 +02:00
Alexander Larsson
f9d77959a4 Don't create GdkWindows with NULL parents
This is not multi-display safe, you always need to pick the right
parent based on which screen your widget is at.
2012-09-27 13:46:26 +02:00
Carlos Garnacho
81045779f6 Improve CSS styling of touch text selection handles
Don't hook on the widget style context and set up instead
a widget path for itself. Also use a common style class
for both handles, with an extra top/bottom class for each
handle.
2012-09-03 17:08:02 +02:00
Carlos Garnacho
1f7e375c33 Add GtkTextHandle
This is a helper object to allow text widgets to implement
text selection on touch devices. It allows for both cursor
placement and text selection, displaying draggable handles
on/around the cursor and selection bound positions.

Currently, this is private to GTK+, and only available to
GtkEntry and GtkTextView.
2012-09-03 00:19:03 -04:00