summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c40
1 files changed, 7 insertions, 33 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 11b92e63..ff1c577a 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -76,13 +76,11 @@ struct Impl_Model {
76 /* state that persists across sessions */ 76 /* state that persists across sessions */
77 iHistory *history; 77 iHistory *history;
78 iString * url; 78 iString * url;
79 int textSizePercent;
80}; 79};
81 80
82void init_Model(iModel *d) { 81void init_Model(iModel *d) {
83 d->history = new_History(); 82 d->history = new_History();
84 d->url = new_String(); 83 d->url = new_String();
85 d->textSizePercent = 100;
86} 84}
87 85
88void deinit_Model(iModel *d) { 86void deinit_Model(iModel *d) {
@@ -92,13 +90,13 @@ void deinit_Model(iModel *d) {
92 90
93void serialize_Model(const iModel *d, iStream *outs) { 91void serialize_Model(const iModel *d, iStream *outs) {
94 serialize_String(d->url, outs); 92 serialize_String(d->url, outs);
95 write16_Stream(outs, d->textSizePercent); 93 write16_Stream(outs, 0 /*d->zoomPercent*/);
96 serialize_History(d->history, outs); 94 serialize_History(d->history, outs);
97} 95}
98 96
99void deserialize_Model(iModel *d, iStream *ins) { 97void deserialize_Model(iModel *d, iStream *ins) {
100 deserialize_String(d->url, ins); 98 deserialize_String(d->url, ins);
101 d->textSizePercent = read16_Stream(ins); 99 /*d->zoomPercent =*/ read16_Stream(ins);
102 deserialize_History(d->history, ins); 100 deserialize_History(d->history, ins);
103} 101}
104 102
@@ -204,7 +202,7 @@ static int documentWidth_DocumentWidget_(const iDocumentWidget *d) {
204 const iWidget *w = constAs_Widget(d); 202 const iWidget *w = constAs_Widget(d);
205 const iRect bounds = bounds_Widget(w); 203 const iRect bounds = bounds_Widget(w);
206 return iMini(bounds.size.x - gap_UI * d->pageMargin * 2, 204 return iMini(bounds.size.x - gap_UI * d->pageMargin * 2,
207 fontSize_UI * 38 * d->mod.textSizePercent / 100); /* TODO: Add user preference .*/ 205 fontSize_UI * 38 * zoom_App() / 100); /* TODO: Add user preference .*/
208} 206}
209 207
210static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { 208static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) {
@@ -559,7 +557,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) {
559 const iGmResponse *resp = recent->cachedResponse; 557 const iGmResponse *resp = recent->cachedResponse;
560 d->state = fetching_RequestState; 558 d->state = fetching_RequestState;
561 /* Use the cached response data. */ 559 /* Use the cached response data. */
562 d->scrollY = d->initialScrollY = recent->scrollY; 560 d->scrollY = d->initialScrollY = recent->scrollY * gap_UI;
563 updateTrust_DocumentWidget_(d, resp); 561 updateTrust_DocumentWidget_(d, resp);
564 updateDocument_DocumentWidget_(d, resp); 562 updateDocument_DocumentWidget_(d, resp);
565 d->state = ready_RequestState; 563 d->state = ready_RequestState;
@@ -602,9 +600,8 @@ void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBoo
602iDocumentWidget *duplicate_DocumentWidget(const iDocumentWidget *orig) { 600iDocumentWidget *duplicate_DocumentWidget(const iDocumentWidget *orig) {
603 iDocumentWidget *d = new_DocumentWidget(); 601 iDocumentWidget *d = new_DocumentWidget();
604 delete_History(d->mod.history); 602 delete_History(d->mod.history);
605 d->mod.textSizePercent = orig->mod.textSizePercent; 603 d->initialScrollY = orig->scrollY;
606 d->initialScrollY = orig->scrollY; 604 d->mod.history = copy_History(orig->mod.history);
607 d->mod.history = copy_History(orig->mod.history);
608 setUrlFromCache_DocumentWidget(d, orig->mod.url, iTrue); 605 setUrlFromCache_DocumentWidget(d, orig->mod.url, iTrue);
609 return d; 606 return d;
610} 607}
@@ -811,20 +808,6 @@ static iBool handleMediaCommand_DocumentWidget_(iDocumentWidget *d, const char *
811 return iFalse; 808 return iFalse;
812} 809}
813 810
814static void changeTextSize_DocumentWidget_(iDocumentWidget *d, int delta) {
815 if (delta == 0) {
816 d->mod.textSizePercent = 100;
817 }
818 else {
819 if (d->mod.textSizePercent < 100 || (delta < 0 && d->mod.textSizePercent == 100)) {
820 delta /= 2;
821 }
822 d->mod.textSizePercent += delta;
823 d->mod.textSizePercent = iClamp(d->mod.textSizePercent, 50, 200);
824 }
825 postCommandf_App("font.setfactor arg:%d", d->mod.textSizePercent);
826}
827
828void updateSize_DocumentWidget(iDocumentWidget *d) { 811void updateSize_DocumentWidget(iDocumentWidget *d) {
829 setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); 812 setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d));
830 updateVisible_DocumentWidget_(d); 813 updateVisible_DocumentWidget_(d);
@@ -1070,15 +1053,6 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1070 case ' ': 1053 case ' ':
1071 postCommand_Widget(w, "scroll.page arg:%d", key == SDLK_PAGEUP ? -1 : +1); 1054 postCommand_Widget(w, "scroll.page arg:%d", key == SDLK_PAGEUP ? -1 : +1);
1072 return iTrue; 1055 return iTrue;
1073 case SDLK_MINUS:
1074 case SDLK_EQUALS:
1075 case SDLK_0:
1076 if (mods == KMOD_PRIMARY) {
1077 changeTextSize_DocumentWidget_(
1078 d, key == SDLK_EQUALS ? 10 : key == SDLK_MINUS ? -10 : 0);
1079 return iTrue;
1080 }
1081 break;
1082 case SDLK_9: { 1056 case SDLK_9: {
1083 iBlock *seed = new_Block(64); 1057 iBlock *seed = new_Block(64);
1084 for (size_t i = 0; i < 64; ++i) { 1058 for (size_t i = 0; i < 64; ++i) {
@@ -1107,7 +1081,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1107 scroll_DocumentWidget_(d, -ev->wheel.y * get_Window()->pixelRatio); 1081 scroll_DocumentWidget_(d, -ev->wheel.y * get_Window()->pixelRatio);
1108#else 1082#else
1109 if (keyMods_Sym(SDL_GetModState()) == KMOD_PRIMARY) { 1083 if (keyMods_Sym(SDL_GetModState()) == KMOD_PRIMARY) {
1110 changeTextSize_DocumentWidget_(d, ev->wheel.y > 0 ? 10 : -10); 1084 postCommandf_App("zoom.delta arg:%d", ev->wheel.y > 0 ? 10 : -10);
1111 return iTrue; 1085 return iTrue;
1112 } 1086 }
1113 scroll_DocumentWidget_(d, -3 * ev->wheel.y * lineHeight_Text(default_FontId)); 1087 scroll_DocumentWidget_(d, -3 * ev->wheel.y * lineHeight_Text(default_FontId));