summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c40
-rw-r--r--src/ui/sidebarwidget.c6
2 files changed, 40 insertions, 6 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index b610b4c5..1aadb6bb 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -233,6 +233,7 @@ enum iDocumentWidgetFlag {
233 drawDownloadCounter_DocumentWidgetFlag = iBit(15), 233 drawDownloadCounter_DocumentWidgetFlag = iBit(15),
234 fromCache_DocumentWidgetFlag = iBit(16), /* don't write anything to cache */ 234 fromCache_DocumentWidgetFlag = iBit(16), /* don't write anything to cache */
235 animationPlaceholder_DocumentWidgetFlag = iBit(17), /* avoid slow operations */ 235 animationPlaceholder_DocumentWidgetFlag = iBit(17), /* avoid slow operations */
236 invalidationPending_DocumentWidgetFlag = iBit(18), /* invalidate as soon as convenient */
236}; 237};
237 238
238enum iDocumentLinkOrdinalMode { 239enum iDocumentLinkOrdinalMode {
@@ -261,6 +262,7 @@ struct Impl_DocumentWidget {
261 iInt2 contextPos; /* coordinates of latest right click */ 262 iInt2 contextPos; /* coordinates of latest right click */
262 int pinchZoomInitial; 263 int pinchZoomInitial;
263 int pinchZoomPosted; 264 int pinchZoomPosted;
265 float swipeSpeed; /* points/sec */
264 iString pendingGotoHeading; 266 iString pendingGotoHeading;
265 267
266 /* Network request: */ 268 /* Network request: */
@@ -1081,8 +1083,17 @@ static void invalidate_DocumentWidget_(iDocumentWidget *d) {
1081 if (flags_Widget(as_Widget(d)) & destroyPending_WidgetFlag) { 1083 if (flags_Widget(as_Widget(d)) & destroyPending_WidgetFlag) {
1082 return; 1084 return;
1083 } 1085 }
1086 if (d->flags & invalidationPending_DocumentWidgetFlag) {
1087 return;
1088 }
1089 if (isAffectedByVisualOffset_Widget(as_Widget(d))) {
1090 d->flags |= invalidationPending_DocumentWidgetFlag;
1091 return;
1092 }
1093 d->flags &= ~invalidationPending_DocumentWidgetFlag;
1084 invalidate_VisBuf(d->visBuf); 1094 invalidate_VisBuf(d->visBuf);
1085 clear_PtrSet(d->invalidRuns); 1095 clear_PtrSet(d->invalidRuns);
1096// printf("[%p] '%s' invalidated\n", d, cstr_String(id_Widget(as_Widget(d))));
1086} 1097}
1087 1098
1088static iRangecc siteText_DocumentWidget_(const iDocumentWidget *d) { 1099static iRangecc siteText_DocumentWidget_(const iDocumentWidget *d) {
@@ -2157,6 +2168,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
2157 iGmResponse *resp = lockResponse_GmRequest(d->request); 2168 iGmResponse *resp = lockResponse_GmRequest(d->request);
2158 if (d->state == fetching_RequestState) { 2169 if (d->state == fetching_RequestState) {
2159 d->state = receivedPartialResponse_RequestState; 2170 d->state = receivedPartialResponse_RequestState;
2171 d->flags &= ~fromCache_DocumentWidgetFlag;
2160 updateTrust_DocumentWidget_(d, resp); 2172 updateTrust_DocumentWidget_(d, resp);
2161 if (isSuccess_GmStatusCode(statusCode)) { 2173 if (isSuccess_GmStatusCode(statusCode)) {
2162 clear_Banner(d->banner); 2174 clear_Banner(d->banner);
@@ -2309,6 +2321,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
2309 } 2321 }
2310 } 2322 }
2311 else if (d->state == receivedPartialResponse_RequestState) { 2323 else if (d->state == receivedPartialResponse_RequestState) {
2324 d->flags &= ~fromCache_DocumentWidgetFlag;
2312 switch (category_GmStatusCode(statusCode)) { 2325 switch (category_GmStatusCode(statusCode)) {
2313 case categorySuccess_GmStatusCode: 2326 case categorySuccess_GmStatusCode:
2314 /* More content available. */ 2327 /* More content available. */
@@ -2664,8 +2677,13 @@ static void setupSwipeOverlay_DocumentWidget_(iDocumentWidget *d, iWidget *overl
2664 setFlags_Widget(as_Widget(d), refChildrenOffset_WidgetFlag, iTrue); 2677 setFlags_Widget(as_Widget(d), refChildrenOffset_WidgetFlag, iTrue);
2665 as_Widget(d)->offsetRef = swipeParent; 2678 as_Widget(d)->offsetRef = swipeParent;
2666 /* `overlay` animates off the screen to the right. */ 2679 /* `overlay` animates off the screen to the right. */
2667 setVisualOffset_Widget(overlay, value_Anim(&w->visualOffset), 0, 0); 2680 const int fromPos = value_Anim(&w->visualOffset);
2668 setVisualOffset_Widget(overlay, width_Widget(overlay), 150, 0); 2681 const int toPos = width_Widget(overlay);
2682 setVisualOffset_Widget(overlay, fromPos, 0, 0);
2683 float swipe = iClamp(d->swipeSpeed, 400, 1000) * gap_UI;
2684 uint32_t span = ((toPos - fromPos) / swipe) * 1000;
2685// printf("from:%d to:%d swipe:%f span:%u\n", fromPos, toPos, d->swipeSpeed, span);
2686 setVisualOffset_Widget(overlay, toPos, span, 0);
2669 setVisualOffset_Widget(w, 0, 0, 0); 2687 setVisualOffset_Widget(w, 0, 0, 0);
2670} 2688}
2671 2689
@@ -2791,12 +2809,13 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
2791 return iTrue; 2809 return iTrue;
2792 } 2810 }
2793 setFlags_Widget(w, dragged_WidgetFlag, iFalse); 2811 setFlags_Widget(w, dragged_WidgetFlag, iFalse);
2794 setVisualOffset_Widget(w, 0, 150, 0); 2812 setVisualOffset_Widget(w, 0, 250, easeOut_AnimFlag | softer_AnimFlag);
2795 return iTrue; 2813 return iTrue;
2796 } 2814 }
2797 if (equal_Command(cmd, "edgeswipe.ended") && argLabel_Command(cmd, "side") == 1) { 2815 if (equal_Command(cmd, "edgeswipe.ended") && argLabel_Command(cmd, "side") == 1) {
2798 iWidget *swipeParent = swipeParent_DocumentWidget_(d); 2816 iWidget *swipeParent = swipeParent_DocumentWidget_(d);
2799 iDocumentWidget *swipeIn = findChild_Widget(swipeParent, "swipein"); 2817 iDocumentWidget *swipeIn = findChild_Widget(swipeParent, "swipein");
2818 d->swipeSpeed = argLabel_Command(cmd, "speed") / gap_UI;
2800 /* "swipe.back" will soon follow. The `d` document will do the actual back navigation, 2819 /* "swipe.back" will soon follow. The `d` document will do the actual back navigation,
2801 switching immediately to a cached page. However, if one is not available, we'll need 2820 switching immediately to a cached page. However, if one is not available, we'll need
2802 to show a blank page for a while. */ 2821 to show a blank page for a while. */
@@ -2858,6 +2877,9 @@ static iBool cancelRequest_DocumentWidget_(iDocumentWidget *d, iBool postBack) {
2858static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { 2877static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
2859 iWidget *w = as_Widget(d); 2878 iWidget *w = as_Widget(d);
2860 if (equal_Command(cmd, "document.openurls.changed")) { 2879 if (equal_Command(cmd, "document.openurls.changed")) {
2880 if (d->flags & animationPlaceholder_DocumentWidgetFlag) {
2881 return iFalse;
2882 }
2861 /* When any tab changes its document URL, update the open link indicators. */ 2883 /* When any tab changes its document URL, update the open link indicators. */
2862 if (updateOpenURLs_GmDocument(d->doc)) { 2884 if (updateOpenURLs_GmDocument(d->doc)) {
2863 invalidate_DocumentWidget_(d); 2885 invalidate_DocumentWidget_(d);
@@ -3179,6 +3201,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
3179 } 3201 }
3180 else if (equalWidget_Command(cmd, w, "document.request.finished") && 3202 else if (equalWidget_Command(cmd, w, "document.request.finished") &&
3181 id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) { 3203 id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) {
3204 d->flags &= ~fromCache_DocumentWidgetFlag;
3182 set_Block(&d->sourceContent, body_GmRequest(d->request)); 3205 set_Block(&d->sourceContent, body_GmRequest(d->request));
3183 if (!isSuccess_GmStatusCode(status_GmRequest(d->request))) { 3206 if (!isSuccess_GmStatusCode(status_GmRequest(d->request))) {
3184 /* TODO: Why is this here? Can it be removed? */ 3207 /* TODO: Why is this here? Can it be removed? */
@@ -5149,6 +5172,16 @@ static void prerender_DocumentWidget_(iAny *context) {
5149 } 5172 }
5150} 5173}
5151 5174
5175static void checkPendingInvalidation_DocumentWidget_(const iDocumentWidget *d) {
5176 if (d->flags & invalidationPending_DocumentWidgetFlag &&
5177 !isAffectedByVisualOffset_Widget(constAs_Widget(d))) {
5178// printf("%p visoff: %d\n", d, left_Rect(bounds_Widget(w)) - left_Rect(boundsWithoutVisualOffset_Widget(w)));
5179 iDocumentWidget *m = (iDocumentWidget *) d; /* Hrrm, not const... */
5180 m->flags &= ~invalidationPending_DocumentWidgetFlag;
5181 invalidate_DocumentWidget_(m);
5182 }
5183}
5184
5152static void draw_DocumentWidget_(const iDocumentWidget *d) { 5185static void draw_DocumentWidget_(const iDocumentWidget *d) {
5153 const iWidget *w = constAs_Widget(d); 5186 const iWidget *w = constAs_Widget(d);
5154 const iRect bounds = bounds_Widget(w); 5187 const iRect bounds = bounds_Widget(w);
@@ -5157,6 +5190,7 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) {
5157 if (width_Rect(bounds) <= 0) { 5190 if (width_Rect(bounds) <= 0) {
5158 return; 5191 return;
5159 } 5192 }
5193 checkPendingInvalidation_DocumentWidget_(d);
5160 /* Each document has its own palette, but the drawing routines rely on a global one. 5194 /* Each document has its own palette, but the drawing routines rely on a global one.
5161 As we're now drawing a document, ensure that the right palette is in effect. 5195 As we're now drawing a document, ensure that the right palette is in effect.
5162 Document theme colors can be used elsewhere, too, but first a document's palette 5196 Document theme colors can be used elsewhere, too, but first a document's palette
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index dcce724a..26473322 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -1809,14 +1809,14 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1809 enum iWidgetTouchMode touchMode = widgetMode_Touch(w); 1809 enum iWidgetTouchMode touchMode = widgetMode_Touch(w);
1810 if (touchMode == momentum_WidgetTouchMode) { 1810 if (touchMode == momentum_WidgetTouchMode) {
1811 /* We don't do momentum. */ 1811 /* We don't do momentum. */
1812 float swipe = stopWidgetMomentum_Touch(w); 1812 float swipe = stopWidgetMomentum_Touch(w) / gap_UI;
1813// printf("swipe: %f\n", swipe); 1813// printf("swipe: %f\n", swipe);
1814 const iRangei midRegion = SlidingSheetMiddleRegion_SidebarWidget_(d); 1814 const iRangei midRegion = SlidingSheetMiddleRegion_SidebarWidget_(d);
1815 const int pos = top_Rect(w->rect); 1815 const int pos = top_Rect(w->rect);
1816 if (swipe < 500) { 1816 if (swipe < 170) {
1817 gotoNearestSlidingSheetPos_SidebarWidget_(d); 1817 gotoNearestSlidingSheetPos_SidebarWidget_(d);
1818 } 1818 }
1819 else if (swipe > 6500 && ev->wheel.y > 0) { 1819 else if (swipe > 500 && ev->wheel.y > 0) {
1820 /* Fast swipe down will dismiss. */ 1820 /* Fast swipe down will dismiss. */
1821 setSlidingSheetPos_SidebarWidget_(d, bottom_SlidingSheetPos); 1821 setSlidingSheetPos_SidebarWidget_(d, bottom_SlidingSheetPos);
1822 } 1822 }