diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-14 12:40:17 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-14 12:40:17 +0200 |
commit | c9b1a0d3e42d27ec2786103ec3bc812a5d38da6c (patch) | |
tree | 5455f1354e4911d6a52a3ddfba2f405f48e0a1f8 /src/ui/documentwidget.c | |
parent | e093892eddf5481b310aac5d66b775d3e1c013cf (diff) |
Navigating to parent directory or site root
Added keyboard shortcuts for navigating up to the parent directory and to the site root.
Clicking the top banner also navigates to the site root.
IssueID #29
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 70 |
1 files changed, 52 insertions, 18 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index c71758be..3fc7e841 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -225,6 +225,8 @@ void init_DocumentWidget(iDocumentWidget *d) { | |||
225 | #endif | 225 | #endif |
226 | addAction_Widget(w, navigateBack_KeyShortcut, "navigate.back"); | 226 | addAction_Widget(w, navigateBack_KeyShortcut, "navigate.back"); |
227 | addAction_Widget(w, navigateForward_KeyShortcut, "navigate.forward"); | 227 | addAction_Widget(w, navigateForward_KeyShortcut, "navigate.forward"); |
228 | addAction_Widget(w, navigateParent_KeyShortcut, "navigate.parent"); | ||
229 | addAction_Widget(w, navigateRoot_KeyShortcut, "navigate.root"); | ||
228 | } | 230 | } |
229 | 231 | ||
230 | void deinit_DocumentWidget(iDocumentWidget *d) { | 232 | void deinit_DocumentWidget(iDocumentWidget *d) { |
@@ -259,13 +261,6 @@ static void requestUpdated_DocumentWidget_(iAnyObject *obj) { | |||
259 | } | 261 | } |
260 | } | 262 | } |
261 | 263 | ||
262 | #if 0 | ||
263 | static void requestTimedOut_DocumentWidget_(iAnyObject *obj) { | ||
264 | iDocumentWidget *d = obj; | ||
265 | postCommandf_App("document.request.timeout doc:%p request:%p", d, d->request); | ||
266 | } | ||
267 | #endif | ||
268 | |||
269 | static void requestFinished_DocumentWidget_(iAnyObject *obj) { | 264 | static void requestFinished_DocumentWidget_(iAnyObject *obj) { |
270 | iDocumentWidget *d = obj; | 265 | iDocumentWidget *d = obj; |
271 | postCommand_Widget(obj, "document.request.finished doc:%p request:%p", d, d->request); | 266 | postCommand_Widget(obj, "document.request.finished doc:%p request:%p", d, d->request); |
@@ -301,6 +296,16 @@ static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { | |||
301 | return rect; | 296 | return rect; |
302 | } | 297 | } |
303 | 298 | ||
299 | static iRect siteBannerRect_DocumentWidget_(const iDocumentWidget *d) { | ||
300 | const iGmRun *banner = siteBanner_GmDocument(d->doc); | ||
301 | if (!banner) { | ||
302 | return zero_Rect(); | ||
303 | } | ||
304 | const iRect docBounds = documentBounds_DocumentWidget_(d); | ||
305 | const iInt2 origin = addY_I2(topLeft_Rect(docBounds), -value_Anim(&d->scrollY)); | ||
306 | return moved_Rect(banner->visBounds, origin); | ||
307 | } | ||
308 | |||
304 | static int forceBreakWidth_DocumentWidget_(const iDocumentWidget *d) { | 309 | static int forceBreakWidth_DocumentWidget_(const iDocumentWidget *d) { |
305 | if (equalCase_Rangecc(urlScheme_String(d->mod.url), "gopher")) { | 310 | if (equalCase_Rangecc(urlScheme_String(d->mod.url), "gopher")) { |
306 | return documentWidth_DocumentWidget_(d); | 311 | return documentWidth_DocumentWidget_(d); |
@@ -1397,13 +1402,6 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1397 | postCommandf_App("document.changed url:%s", cstr_String(d->mod.url)); | 1402 | postCommandf_App("document.changed url:%s", cstr_String(d->mod.url)); |
1398 | return iFalse; | 1403 | return iFalse; |
1399 | } | 1404 | } |
1400 | #if 0 | ||
1401 | else if (equal_Command(cmd, "document.request.timeout") && | ||
1402 | pointerLabel_Command(cmd, "request") == d->request) { | ||
1403 | cancel_GmRequest(d->request); | ||
1404 | return iFalse; | ||
1405 | } | ||
1406 | #endif | ||
1407 | else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) { | 1405 | else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) { |
1408 | return handleMediaCommand_DocumentWidget_(d, cmd); | 1406 | return handleMediaCommand_DocumentWidget_(d, cmd); |
1409 | } | 1407 | } |
@@ -1528,6 +1526,32 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1528 | goForward_History(d->mod.history); | 1526 | goForward_History(d->mod.history); |
1529 | return iTrue; | 1527 | return iTrue; |
1530 | } | 1528 | } |
1529 | else if (equal_Command(cmd, "navigate.parent") && document_App() == d) { | ||
1530 | iUrl parts; | ||
1531 | init_Url(&parts, d->mod.url); | ||
1532 | /* Remove the last path segment. */ | ||
1533 | if (size_Range(&parts.path) > 1) { | ||
1534 | if (parts.path.end[-1] == '/') { | ||
1535 | parts.path.end--; | ||
1536 | } | ||
1537 | while (parts.path.end > parts.path.start) { | ||
1538 | if (parts.path.end[-1] == '/') break; | ||
1539 | parts.path.end--; | ||
1540 | } | ||
1541 | postCommandf_App( | ||
1542 | "open url:%s", | ||
1543 | cstr_Rangecc((iRangecc){ constBegin_String(d->mod.url), parts.path.end })); | ||
1544 | } | ||
1545 | return iTrue; | ||
1546 | } | ||
1547 | else if (equal_Command(cmd, "navigate.root") && document_App() == d) { | ||
1548 | iUrl parts; | ||
1549 | init_Url(&parts, d->mod.url); | ||
1550 | postCommandf_App( | ||
1551 | "open url:%s/", | ||
1552 | cstr_Rangecc((iRangecc){ constBegin_String(d->mod.url), parts.path.start })); | ||
1553 | return iTrue; | ||
1554 | } | ||
1531 | else if (equalWidget_Command(cmd, w, "scroll.moved")) { | 1555 | else if (equalWidget_Command(cmd, w, "scroll.moved")) { |
1532 | init_Anim(&d->scrollY, arg_Command(cmd)); | 1556 | init_Anim(&d->scrollY, arg_Command(cmd)); |
1533 | updateVisible_DocumentWidget_(d); | 1557 | updateVisible_DocumentWidget_(d); |
@@ -1922,11 +1946,15 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1922 | } | 1946 | } |
1923 | else if (ev->type == SDL_MOUSEMOTION) { | 1947 | else if (ev->type == SDL_MOUSEMOTION) { |
1924 | iChangeFlags(d->flags, noHoverWhileScrolling_DocumentWidgetFlag, iFalse); | 1948 | iChangeFlags(d->flags, noHoverWhileScrolling_DocumentWidgetFlag, iFalse); |
1949 | const iInt2 mpos = init_I2(ev->motion.x, ev->motion.y); | ||
1925 | if (isVisible_Widget(d->menu)) { | 1950 | if (isVisible_Widget(d->menu)) { |
1926 | setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_ARROW); | 1951 | setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_ARROW); |
1927 | } | 1952 | } |
1953 | else if (contains_Rect(siteBannerRect_DocumentWidget_(d), mpos)) { | ||
1954 | setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_HAND); | ||
1955 | } | ||
1928 | else { | 1956 | else { |
1929 | updateHover_DocumentWidget_(d, init_I2(ev->motion.x, ev->motion.y)); | 1957 | updateHover_DocumentWidget_(d, mpos); |
1930 | } | 1958 | } |
1931 | updateOutlineOpacity_DocumentWidget_(d); | 1959 | updateOutlineOpacity_DocumentWidget_(d); |
1932 | } | 1960 | } |
@@ -2006,11 +2034,13 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
2006 | (iMenuItem[]){ | 2034 | (iMenuItem[]){ |
2007 | { "Go Back", navigateBack_KeyShortcut, "navigate.back" }, | 2035 | { "Go Back", navigateBack_KeyShortcut, "navigate.back" }, |
2008 | { "Go Forward", navigateForward_KeyShortcut, "navigate.forward" }, | 2036 | { "Go Forward", navigateForward_KeyShortcut, "navigate.forward" }, |
2037 | { "Go to Parent", navigateParent_KeyShortcut, "navigate.parent" }, | ||
2038 | { "Go to Root", navigateRoot_KeyShortcut, "navigate.root" }, | ||
2039 | { "---", 0, 0, NULL }, | ||
2009 | { "Reload Page", reload_KeyShortcut, "navigate.reload" }, | 2040 | { "Reload Page", reload_KeyShortcut, "navigate.reload" }, |
2010 | { "---", 0, 0, NULL }, | 2041 | { "---", 0, 0, NULL }, |
2011 | { "Copy Page URL", 0, 0, "document.copylink" }, | 2042 | { "Copy Page URL", 0, 0, "document.copylink" } }, |
2012 | { "---", 0, 0, NULL } }, | 2043 | 8); |
2013 | 6); | ||
2014 | if (isEmpty_Range(&d->selectMark)) { | 2044 | if (isEmpty_Range(&d->selectMark)) { |
2015 | pushBackN_Array( | 2045 | pushBackN_Array( |
2016 | &items, | 2046 | &items, |
@@ -2144,6 +2174,10 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
2144 | d->selectMark = iNullRange; | 2174 | d->selectMark = iNullRange; |
2145 | refresh_Widget(w); | 2175 | refresh_Widget(w); |
2146 | } | 2176 | } |
2177 | /* Clicking on the top/side banner navigates to site root. */ | ||
2178 | if (contains_Rect(siteBannerRect_DocumentWidget_(d), pos_Click(&d->click))) { | ||
2179 | postCommand_Widget(d, "navigate.root"); | ||
2180 | } | ||
2147 | } | 2181 | } |
2148 | return iTrue; | 2182 | return iTrue; |
2149 | case double_ClickResult: | 2183 | case double_ClickResult: |