summaryrefslogtreecommitdiff
path: root/src/ui/root.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/root.c')
-rw-r--r--src/ui/root.c132
1 files changed, 77 insertions, 55 deletions
diff --git a/src/ui/root.c b/src/ui/root.c
index 76ef05c4..6cf3f424 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -269,6 +269,7 @@ iAnyObject *findWidget_Root(const char *id) {
269} 269}
270 270
271void destroyPending_Root(iRoot *d) { 271void destroyPending_Root(iRoot *d) {
272 iRoot *oldRoot = current_Root();
272 setCurrent_Root(d); 273 setCurrent_Root(d);
273 iForEach(PtrSet, i, d->pendingDestruction) { 274 iForEach(PtrSet, i, d->pendingDestruction) {
274 iWidget *widget = *i.value; 275 iWidget *widget = *i.value;
@@ -282,7 +283,7 @@ void destroyPending_Root(iRoot *d) {
282 iRelease(widget); 283 iRelease(widget);
283 remove_PtrSetIterator(&i); 284 remove_PtrSetIterator(&i);
284 } 285 }
285 setCurrent_Root(NULL); 286 setCurrent_Root(oldRoot);
286} 287}
287 288
288void postArrange_Root(iRoot *d) { 289void postArrange_Root(iRoot *d) {
@@ -349,6 +350,7 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) {
349 } 350 }
350 else if (equal_Command(cmd, "input.resized")) { 351 else if (equal_Command(cmd, "input.resized")) {
351 /* No parent handled this, so do a full rearrangement. */ 352 /* No parent handled this, so do a full rearrangement. */
353 /* TODO: Defer this and do a single rearrangement later. */
352 arrange_Widget(root); 354 arrange_Widget(root);
353 postRefresh_App(); 355 postRefresh_App();
354 return iTrue; 356 return iTrue;
@@ -414,6 +416,7 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) {
414 else { 416 else {
415 addChildPos_Widget(findChild_Widget(root, "stack"), iClob(sidebar), back_WidgetAddPos); 417 addChildPos_Widget(findChild_Widget(root, "stack"), iClob(sidebar), back_WidgetAddPos);
416 setWidth_SidebarWidget(sidebar, (float) width_Widget(root) / (float) gap_UI); 418 setWidth_SidebarWidget(sidebar, (float) width_Widget(root) / (float) gap_UI);
419 setWidth_SidebarWidget(sidebar2, (float) width_Widget(root) / (float) gap_UI);
417 } 420 }
418 return iFalse; 421 return iFalse;
419 } 422 }
@@ -466,11 +469,11 @@ static void setReloadLabel_Root_(iRoot *d, iBool animating) {
466 const iBool isMobile = deviceType_App() != desktop_AppDeviceType; 469 const iBool isMobile = deviceType_App() != desktop_AppDeviceType;
467 iLabelWidget *label = findChild_Widget(d->widget, "reload"); 470 iLabelWidget *label = findChild_Widget(d->widget, "reload");
468 updateTextCStr_LabelWidget( 471 updateTextCStr_LabelWidget(
469 label, animating ? loadAnimationCStr_() : (isMobile ? pageMenuCStr_ : reloadCStr_)); 472 label, animating ? loadAnimationCStr_() : (/*isMobile ? pageMenuCStr_ :*/ reloadCStr_));
470 if (isMobile) { 473// if (isMobile) {
471 setCommand_LabelWidget(label, 474// setCommand_LabelWidget(label,
472 collectNewCStr_String(animating ? "navigate.reload" : "menu.open")); 475// collectNewCStr_String(animating ? "navigate.reload" : "menu.open"));
473 } 476// }
474} 477}
475 478
476static void checkLoadAnimation_Root_(iRoot *d) { 479static void checkLoadAnimation_Root_(iRoot *d) {
@@ -536,9 +539,12 @@ static iBool willPerformSearchQuery_(const iString *userInput) {
536 539
537static void updateUrlInputContentPadding_(iWidget *navBar) { 540static void updateUrlInputContentPadding_(iWidget *navBar) {
538 iInputWidget *url = findChild_Widget(navBar, "url"); 541 iInputWidget *url = findChild_Widget(navBar, "url");
539 const iWidget *indicators = findChild_Widget(navBar, "url.rightembed"); 542 const int lockWidth = width_Widget(findChild_Widget(navBar, "navbar.lock"));
540 setContentPadding_InputWidget(url, -1, 543 const int indicatorsWidth = width_Widget(findChild_Widget(navBar, "url.rightembed"));
541 width_Widget(indicators)); 544 /* The indicators widget has a padding that covers the urlButtons area. */
545 setContentPadding_InputWidget(url,
546 lockWidth - 2 * gap_UI, // * 0.75f,
547 indicatorsWidth);
542} 548}
543 549
544static void showSearchQueryIndicator_(iBool show) { 550static void showSearchQueryIndicator_(iBool show) {
@@ -585,17 +591,17 @@ static void updateNavBarSize_(iWidget *navBar) {
585 updateSize_LabelWidget(label); 591 updateSize_LabelWidget(label);
586 } 592 }
587 } 593 }
594 updateUrlInputContentPadding_(navBar);
588 /* Note that InputWidget uses the `tight` flag to adjust its inner padding. */ 595 /* Note that InputWidget uses the `tight` flag to adjust its inner padding. */
589 /* TODO: Is this redundant? See `updateMetrics_Window_()`. */ 596// const int embedButtonWidth = width_Widget(findChild_Widget(navBar, "navbar.lock"));
590 const int embedButtonWidth = width_Widget(findChild_Widget(navBar, "navbar.lock")); 597// setContentPadding_InputWidget(findChild_Widget(navBar, "url"),
591 setContentPadding_InputWidget(findChild_Widget(navBar, "url"), 598// embedButtonWidth * 0.75f,
592 embedButtonWidth * 0.75f, 599// embedButtonWidth * 0.75f);
593 embedButtonWidth * 0.75f);
594 } 600 }
595 if (isPhone) { 601 if (isPhone) {
596 static const char *buttons[] = { "navbar.back", "navbar.forward", "navbar.sidebar", 602 static const char *buttons[] = { "navbar.back", "navbar.forward", "navbar.sidebar",
597 "navbar.ident", "navbar.home", "navbar.menu" }; 603 "navbar.ident", "navbar.home", "navbar.menu" };
598 iWidget *toolBar = findWidget_App("toolbar"); 604 iWidget *toolBar = findWidget_Root("toolbar");
599 setVisualOffset_Widget(toolBar, 0, 0, 0); 605 setVisualOffset_Widget(toolBar, 0, 0, 0);
600 setFlags_Widget(toolBar, hidden_WidgetFlag, isLandscape_App()); 606 setFlags_Widget(toolBar, hidden_WidgetFlag, isLandscape_App());
601 iForIndices(i, buttons) { 607 iForIndices(i, buttons) {
@@ -901,15 +907,19 @@ void updateMetrics_Root(iRoot *d) {
901 iWidget *url = findChild_Widget(d->widget, "url"); 907 iWidget *url = findChild_Widget(d->widget, "url");
902 iWidget *rightEmbed = findChild_Widget(navBar, "url.rightembed"); 908 iWidget *rightEmbed = findChild_Widget(navBar, "url.rightembed");
903 iWidget *embedPad = findChild_Widget(navBar, "url.embedpad"); 909 iWidget *embedPad = findChild_Widget(navBar, "url.embedpad");
910 iWidget *urlButtons = findChild_Widget(navBar, "url.buttons");
904 setPadding_Widget(as_Widget(url), 0, gap_UI, 0, gap_UI); 911 setPadding_Widget(as_Widget(url), 0, gap_UI, 0, gap_UI);
905 navBar->rect.size.y = 0; /* recalculate height based on children (FIXME: shouldn't be needed) */ 912 navBar->rect.size.y = 0; /* recalculate height based on children (FIXME: shouldn't be needed) */
906 updateSize_LabelWidget((iLabelWidget *) lock); 913// updateSize_LabelWidget((iLabelWidget *) lock);
907 setFixedSize_Widget(embedPad, init_I2(width_Widget(lock) + gap_UI / 2, 1)); 914// updateSize_LabelWidget((iLabelWidget *) findChild_Widget(navBar, "reload"));
908 setContentPadding_InputWidget((iInputWidget *) url, width_Widget(lock) * 0.75, 915// arrange_Widget(urlButtons);
909 width_Widget(lock) * 0.75); 916 setFixedSize_Widget(embedPad, init_I2(width_Widget(urlButtons) + gap_UI / 2, 1));
917// setContentPadding_InputWidget((iInputWidget *) url, width_Widget(lock) * 0.75,
918// width_Widget(lock) * 0.75);
910 rightEmbed->rect.pos.y = gap_UI; 919 rightEmbed->rect.pos.y = gap_UI;
911 updatePadding_Root(d); 920 updatePadding_Root(d);
912 arrange_Widget(d->widget); 921 arrange_Widget(d->widget);
922 updateUrlInputContentPadding_(navBar);
913 postRefresh_App(); 923 postRefresh_App();
914} 924}
915 925
@@ -1057,7 +1067,7 @@ void createUserInterface_Root(iRoot *d) {
1057 setNoAutoMinHeight_LabelWidget(fprog, iTrue); 1067 setNoAutoMinHeight_LabelWidget(fprog, iTrue);
1058 addChildFlags_Widget(rightEmbed, 1068 addChildFlags_Widget(rightEmbed,
1059 iClob(fprog), 1069 iClob(fprog),
1060 collapse_WidgetFlag | frameless_WidgetFlag | hidden_WidgetFlag); 1070 collapse_WidgetFlag | hidden_WidgetFlag | frameless_WidgetFlag);
1061 } 1071 }
1062 /* Download progress indicator is also inside the input field, but hidden normally. */ { 1072 /* Download progress indicator is also inside the input field, but hidden normally. */ {
1063 iLabelWidget *progress = new_LabelWidget(uiTextCaution_ColorEscape "00.000 ${mb}", NULL); 1073 iLabelWidget *progress = new_LabelWidget(uiTextCaution_ColorEscape "00.000 ${mb}", NULL);
@@ -1066,7 +1076,7 @@ void createUserInterface_Root(iRoot *d) {
1066 setAlignVisually_LabelWidget(progress, iTrue); 1076 setAlignVisually_LabelWidget(progress, iTrue);
1067 setNoAutoMinHeight_LabelWidget(progress, iTrue); 1077 setNoAutoMinHeight_LabelWidget(progress, iTrue);
1068 addChildFlags_Widget( 1078 addChildFlags_Widget(
1069 rightEmbed, iClob(progress), collapse_WidgetFlag); 1079 rightEmbed, iClob(progress), collapse_WidgetFlag | hidden_WidgetFlag);
1070 } 1080 }
1071 /* Pinning indicator. */ { 1081 /* Pinning indicator. */ {
1072 iLabelWidget *pin = new_LabelWidget(uiTextAction_ColorEscape leftHalf_Icon, NULL); 1082 iLabelWidget *pin = new_LabelWidget(uiTextAction_ColorEscape leftHalf_Icon, NULL);
@@ -1076,39 +1086,44 @@ void createUserInterface_Root(iRoot *d) {
1076 setNoAutoMinHeight_LabelWidget(pin, iTrue); 1086 setNoAutoMinHeight_LabelWidget(pin, iTrue);
1077 addChildFlags_Widget(rightEmbed, 1087 addChildFlags_Widget(rightEmbed,
1078 iClob(pin), 1088 iClob(pin),
1079 collapse_WidgetFlag | tight_WidgetFlag | frameless_WidgetFlag); 1089 collapse_WidgetFlag | hidden_WidgetFlag | tight_WidgetFlag | frameless_WidgetFlag);
1090 }
1091 iWidget *urlButtons = new_Widget();
1092 setId_Widget(urlButtons, "url.buttons");
1093 setFlags_Widget(urlButtons, embedFlags | arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
1094 /* Mobile page menu. */
1095 if (deviceType_App() != desktop_AppDeviceType) {
1096 iLabelWidget *pageMenuButton;
1097 /* In a mobile layout, the reload button is replaced with the Page/Ellipsis menu. */
1098 pageMenuButton = makeMenuButton_LabelWidget(pageMenuCStr_,
1099 (iMenuItem[]){
1100 { upArrow_Icon " ${menu.parent}", navigateParent_KeyShortcut, "navigate.parent" },
1101 { upArrowBar_Icon " ${menu.root}", navigateRoot_KeyShortcut, "navigate.root" },
1102 { timer_Icon " ${menu.autoreload}", 0, 0, "document.autoreload.menu" },
1103 { "---", 0, 0, NULL },
1104 { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
1105 { star_Icon " ${menu.page.subscribe}", subscribeToPage_KeyModifier, "feeds.subscribe" },
1106 { book_Icon " ${menu.page.import}", 0, 0, "bookmark.links confirm:1" },
1107 { globe_Icon " ${menu.page.translate}", 0, 0, "document.translate" },
1108 { "---", 0, 0, NULL },
1109 { "${menu.page.copyurl}", 0, 0, "document.copylink" },
1110 { "${menu.page.copysource}", 'c', KMOD_PRIMARY, "copy" },
1111 { download_Icon " " saveToDownloads_Label, SDLK_s, KMOD_PRIMARY, "document.save" } },
1112 12);
1113 setId_Widget(as_Widget(pageMenuButton), "pagemenubutton");
1114 setFont_LabelWidget(pageMenuButton, uiContentBold_FontId);
1115 setAlignVisually_LabelWidget(pageMenuButton, iTrue);
1116 addChildFlags_Widget(urlButtons, iClob(pageMenuButton), embedFlags);
1117 updateSize_LabelWidget(pageMenuButton);
1080 } 1118 }
1081 /* Reload button. */ { 1119 /* Reload button. */ {
1082 iLabelWidget *reload; 1120 iLabelWidget *reload = newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload");
1083 if (deviceType_App() == desktop_AppDeviceType) {
1084 reload = newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload");
1085 }
1086 else {
1087 /* In a mobile layout, the reload button is replaced with the Page/Ellipsis menu. */
1088 reload = makeMenuButton_LabelWidget(pageMenuCStr_,
1089 (iMenuItem[]){
1090 { reload_Icon " ${menu.reload}", reload_KeyShortcut, "navigate.reload" },
1091 { timer_Icon " ${menu.autoreload}", 0, 0, "document.autoreload.menu" },
1092 { "---", 0, 0, NULL },
1093 { upArrow_Icon " ${menu.parent}", navigateParent_KeyShortcut, "navigate.parent" },
1094 { upArrowBar_Icon " ${menu.root}", navigateRoot_KeyShortcut, "navigate.root" },
1095 { "---", 0, 0, NULL },
1096 { pin_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
1097 { star_Icon " ${menu.page.subscribe}", subscribeToPage_KeyModifier, "feeds.subscribe" },
1098 { book_Icon " ${menu.page.import}", 0, 0, "bookmark.links confirm:1" },
1099 { globe_Icon " ${menu.page.translate}", 0, 0, "document.translate" },
1100 { "---", 0, 0, NULL },
1101 { "${menu.page.copyurl}", 0, 0, "document.copylink" },
1102 { "${menu.page.copysource}", 'c', KMOD_PRIMARY, "copy" },
1103 { download_Icon " " saveToDownloads_Label, SDLK_s, KMOD_PRIMARY, "document.save" } },
1104 14);
1105 setFont_LabelWidget((iLabelWidget *) reload, uiContentBold_FontId);
1106 setAlignVisually_LabelWidget((iLabelWidget *) reload, iTrue);
1107 }
1108 setId_Widget(as_Widget(reload), "reload"); 1121 setId_Widget(as_Widget(reload), "reload");
1109 addChildFlags_Widget(as_Widget(url), iClob(reload), embedFlags | moveToParentRightEdge_WidgetFlag); 1122 addChildFlags_Widget(urlButtons, iClob(reload), embedFlags);
1110 updateSize_LabelWidget(reload); 1123 updateSize_LabelWidget(reload);
1111 } 1124 }
1125 addChildFlags_Widget(as_Widget(url), iClob(urlButtons), moveToParentRightEdge_WidgetFlag);
1126 arrange_Widget(urlButtons);
1112 setId_Widget(addChild_Widget(rightEmbed, iClob(makePadding_Widget(0))), "url.embedpad"); 1127 setId_Widget(addChild_Widget(rightEmbed, iClob(makePadding_Widget(0))), "url.embedpad");
1113 } 1128 }
1114 if (deviceType_App() != desktop_AppDeviceType) { 1129 if (deviceType_App() != desktop_AppDeviceType) {
@@ -1216,7 +1231,9 @@ void createUserInterface_Root(iRoot *d) {
1216 setFlags_Widget(toolBar, moveToParentBottomEdge_WidgetFlag | 1231 setFlags_Widget(toolBar, moveToParentBottomEdge_WidgetFlag |
1217 parentCannotResizeHeight_WidgetFlag | 1232 parentCannotResizeHeight_WidgetFlag |
1218 resizeWidthOfChildren_WidgetFlag | 1233 resizeWidthOfChildren_WidgetFlag |
1219 arrangeHeight_WidgetFlag | arrangeHorizontal_WidgetFlag, iTrue); 1234 arrangeHeight_WidgetFlag | arrangeHorizontal_WidgetFlag |
1235 commandOnClick_WidgetFlag |
1236 drawBackgroundToBottom_WidgetFlag, iTrue);
1220 setBackgroundColor_Widget(toolBar, tmBannerBackground_ColorId); 1237 setBackgroundColor_Widget(toolBar, tmBannerBackground_ColorId);
1221 setId_Widget(addChildFlags_Widget(toolBar, 1238 setId_Widget(addChildFlags_Widget(toolBar,
1222 iClob(newLargeIcon_LabelWidget("\U0001f870", "navigate.back")), 1239 iClob(newLargeIcon_LabelWidget("\U0001f870", "navigate.back")),
@@ -1231,7 +1248,7 @@ void createUserInterface_Root(iRoot *d) {
1231 frameless_WidgetFlag), 1248 frameless_WidgetFlag),
1232 "toolbar.ident"); 1249 "toolbar.ident");
1233 setId_Widget(addChildFlags_Widget(toolBar, 1250 setId_Widget(addChildFlags_Widget(toolBar,
1234 iClob(newLargeIcon_LabelWidget("\U0001f588", "toolbar.showview arg:-1")), 1251 iClob(newLargeIcon_LabelWidget(book_Icon, "toolbar.showview arg:-1")),
1235 frameless_WidgetFlag | commandOnClick_WidgetFlag), 1252 frameless_WidgetFlag | commandOnClick_WidgetFlag),
1236 "toolbar.view"); 1253 "toolbar.view");
1237 iLabelWidget *menuButton = makeMenuButton_LabelWidget("\U0001d362", phoneNavMenuItems_, 1254 iLabelWidget *menuButton = makeMenuButton_LabelWidget("\U0001d362", phoneNavMenuItems_,
@@ -1244,17 +1261,17 @@ void createUserInterface_Root(iRoot *d) {
1244 setFlags_Widget(i.object, noBackground_WidgetFlag, iTrue); 1261 setFlags_Widget(i.object, noBackground_WidgetFlag, iTrue);
1245 setTextColor_LabelWidget(i.object, tmBannerIcon_ColorId); 1262 setTextColor_LabelWidget(i.object, tmBannerIcon_ColorId);
1246 // setBackgroundColor_Widget(i.object, tmBannerSideTitle_ColorId); 1263 // setBackgroundColor_Widget(i.object, tmBannerSideTitle_ColorId);
1247 } 1264 }
1248 const iMenuItem items[] = { 1265 const iMenuItem items[] = {
1249 { pin_Icon " ${sidebar.bookmarks}", 0, 0, "toolbar.showview arg:0" }, 1266 { book_Icon " ${sidebar.bookmarks}", 0, 0, "toolbar.showview arg:0" },
1250 { star_Icon " ${sidebar.feeds}", 0, 0, "toolbar.showview arg:1" }, 1267 { star_Icon " ${sidebar.feeds}", 0, 0, "toolbar.showview arg:1" },
1251 { clock_Icon " ${sidebar.history}", 0, 0, "toolbar.showview arg:2" }, 1268 { clock_Icon " ${sidebar.history}", 0, 0, "toolbar.showview arg:2" },
1252 { page_Icon " ${toolbar.outline}", 0, 0, "toolbar.showview arg:4" }, 1269 { page_Icon " ${toolbar.outline}", 0, 0, "toolbar.showview arg:4" },
1253 }; 1270 };
1254 iWidget *menu = makeMenu_Widget(findChild_Widget(toolBar, "toolbar.view"), 1271 iWidget *menu = makeMenu_Widget(findChild_Widget(toolBar, "toolbar.view"),
1255 items, iElemCount(items)); 1272 items, iElemCount(items));
1256 setId_Widget(menu, "toolbar.menu"); /* view menu */ 1273 setId_Widget(menu, "toolbar.menu"); /* view menu */
1257 } 1274 }
1258#endif 1275#endif
1259 updatePadding_Root(d); 1276 updatePadding_Root(d);
1260 /* Global context menus. */ { 1277 /* Global context menus. */ {
@@ -1319,6 +1336,11 @@ void createUserInterface_Root(iRoot *d) {
1319 } 1336 }
1320 updateMetrics_Root(d); 1337 updateMetrics_Root(d);
1321 updateNavBarSize_(navBar); 1338 updateNavBarSize_(navBar);
1339 if (deviceType_App() == phone_AppDeviceType) {
1340 const float sidebarWidth = width_Widget(root) / (float) gap_UI;
1341 setWidth_SidebarWidget(findChild_Widget(root, "sidebar"), sidebarWidth);
1342 setWidth_SidebarWidget(findChild_Widget(root, "sidebar2"), sidebarWidth);
1343 }
1322} 1344}
1323 1345
1324void showToolbars_Root(iRoot *d, iBool show) { 1346void showToolbars_Root(iRoot *d, iBool show) {