diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/banner.c | 38 | ||||
-rw-r--r-- | src/ui/banner.h | 1 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 39 |
3 files changed, 42 insertions, 36 deletions
diff --git a/src/ui/banner.c b/src/ui/banner.c index 5ec3c9f0..d1ed470c 100644 --- a/src/ui/banner.c +++ b/src/ui/banner.c | |||
@@ -53,6 +53,7 @@ struct Impl_Banner { | |||
53 | iString site; | 53 | iString site; |
54 | iString icon; | 54 | iString icon; |
55 | iArray items; | 55 | iArray items; |
56 | iBool isClick; | ||
56 | }; | 57 | }; |
57 | 58 | ||
58 | iDefineTypeConstruction(Banner) | 59 | iDefineTypeConstruction(Banner) |
@@ -70,6 +71,7 @@ void init_Banner(iBanner *d) { | |||
70 | init_String(&d->site); | 71 | init_String(&d->site); |
71 | init_String(&d->icon); | 72 | init_String(&d->icon); |
72 | init_Array(&d->items, sizeof(iBannerItem)); | 73 | init_Array(&d->items, sizeof(iBannerItem)); |
74 | d->isClick = iFalse; | ||
73 | } | 75 | } |
74 | 76 | ||
75 | void deinit_Banner(iBanner *d) { | 77 | void deinit_Banner(iBanner *d) { |
@@ -96,6 +98,10 @@ int height_Banner(const iBanner *d) { | |||
96 | return d->rect.size.y; | 98 | return d->rect.size.y; |
97 | } | 99 | } |
98 | 100 | ||
101 | iBool contains_Banner(const iBanner *d, iInt2 coord) { | ||
102 | return contains_Rect(d->rect, coord); | ||
103 | } | ||
104 | |||
99 | void clear_Banner(iBanner *d) { | 105 | void clear_Banner(iBanner *d) { |
100 | iForEach(Array, i, &d->items) { | 106 | iForEach(Array, i, &d->items) { |
101 | deinit_BannerItem(i.value); | 107 | deinit_BannerItem(i.value); |
@@ -139,8 +145,36 @@ void remove_Banner(iBanner *d, enum iGmStatusCode code) { | |||
139 | 145 | ||
140 | iBool processEvent_Banner(iBanner *d, const SDL_Event *ev) { | 146 | iBool processEvent_Banner(iBanner *d, const SDL_Event *ev) { |
141 | iWidget *w = as_Widget(d->doc); | 147 | iWidget *w = as_Widget(d->doc); |
142 | /* on motion: */ | 148 | switch (ev->type) { |
143 | // setCursor_Window(window_Widget(w), SDL_SYSTEM_CURSOR_HAND); | 149 | case SDL_MOUSEMOTION: |
150 | if (contains_Rect(d->rect, init_I2(ev->motion.x, ev->motion.y))) { | ||
151 | setCursor_Window(window_Widget(w), SDL_SYSTEM_CURSOR_HAND); | ||
152 | } | ||
153 | break; | ||
154 | case SDL_MOUSEBUTTONDOWN: | ||
155 | case SDL_MOUSEBUTTONUP: | ||
156 | /* Clicking on the top/side banner navigates to site root. */ | ||
157 | if (ev->button.button == SDL_BUTTON_LEFT) { | ||
158 | const iBool isInside = contains_Rect(d->rect, init_I2(ev->button.x, ev->button.y)); | ||
159 | if (isInside && ev->button.state == SDL_PRESSED) { | ||
160 | d->isClick = iTrue; | ||
161 | return iTrue; | ||
162 | } | ||
163 | else if (ev->button.state == SDL_RELEASED) { | ||
164 | if (d->isClick && isInside) { | ||
165 | postCommand_Widget(d->doc, "navigate.root"); | ||
166 | } | ||
167 | d->isClick = iFalse; | ||
168 | } | ||
169 | /* Clicking on a warning? */ | ||
170 | // if (bannerType_DocumentWidget_(d) == certificateWarning_GmDocumentBanner && | ||
171 | // pos_Click(&d->click).y - top_Rect(banRect) > | ||
172 | // lineHeight_Text(banner_FontId) * 2) { | ||
173 | // postCommand_Widget(d, "document.info"); | ||
174 | // } | ||
175 | } | ||
176 | break; | ||
177 | } | ||
144 | return iFalse; | 178 | return iFalse; |
145 | } | 179 | } |
146 | 180 | ||
diff --git a/src/ui/banner.h b/src/ui/banner.h index 5ee8b3ae..2ee3a2bc 100644 --- a/src/ui/banner.h +++ b/src/ui/banner.h | |||
@@ -42,6 +42,7 @@ void setWidth_Banner (iBanner *, int width); | |||
42 | void setPos_Banner (iBanner *, iInt2 pos); | 42 | void setPos_Banner (iBanner *, iInt2 pos); |
43 | 43 | ||
44 | int height_Banner (const iBanner *); | 44 | int height_Banner (const iBanner *); |
45 | iBool contains_Banner (const iBanner *, iInt2 coord); | ||
45 | 46 | ||
46 | iLocalDef iBool isEmpty_Banner(const iBanner *d) { | 47 | iLocalDef iBool isEmpty_Banner(const iBanner *d) { |
47 | return height_Banner(d) == 0; | 48 | return height_Banner(d) == 0; |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 17111ed0..75da67a1 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -342,6 +342,7 @@ void init_DocumentWidget(iDocumentWidget *d) { | |||
342 | d->media = new_ObjectList(); | 342 | d->media = new_ObjectList(); |
343 | d->doc = new_GmDocument(); | 343 | d->doc = new_GmDocument(); |
344 | d->banner = new_Banner(); | 344 | d->banner = new_Banner(); |
345 | setOwner_Banner(d->banner, d); | ||
345 | d->redirectCount = 0; | 346 | d->redirectCount = 0; |
346 | d->ordinalBase = 0; | 347 | d->ordinalBase = 0; |
347 | d->initNormScrollY = 0; | 348 | d->initNormScrollY = 0; |
@@ -540,25 +541,10 @@ static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { | |||
540 | if (docSize.y < rect.size.y) { | 541 | if (docSize.y < rect.size.y) { |
541 | /* Center vertically if short. There is one empty paragraph line's worth of margin | 542 | /* Center vertically if short. There is one empty paragraph line's worth of margin |
542 | between the banner and the page contents. */ | 543 | between the banner and the page contents. */ |
543 | // const int bannerHeight = 0; //banner ? height_Rect(banner->visBounds) : 0; | ||
544 | #if 0 | ||
545 | int offset = iMax(0, (rect.size.y + margin - size_GmDocument(d->doc).y | ||
546 | //- lineHeight_Text(paragraph_FontId) | ||
547 | ) / 2 - height_Banner(d->banner) | ||
548 | //- | ||
549 | //documentTopPad_DocumentWidget_(d) | ||
550 | ); | ||
551 | #endif | ||
552 | int offset = iMax(0, height_Rect(bounds) / 2 | 544 | int offset = iMax(0, height_Rect(bounds) / 2 |
553 | // - (isEmpty_Banner(d->banner) ? lineHeight_Text(paragraph_FontId) / 2 : 0) | ||
554 | - documentTopPad_DocumentWidget_(d) | 545 | - documentTopPad_DocumentWidget_(d) |
555 | // + lineHeight_Text(paragraph_FontId) / 2 | ||
556 | // - isEmpty_Banner(d->banner) ? | ||
557 | - height_Banner(d->banner) | 546 | - height_Banner(d->banner) |
558 | - size_GmDocument(d->doc).y / 2 | 547 | - size_GmDocument(d->doc).y / 2); |
559 | ); | ||
560 | //(//documentTopPad_DocumentWidget_(d) + | ||
561 | //size_GmDocument(d->doc).y) / 2); | ||
562 | rect.pos.y = top_Rect(bounds) + offset; | 548 | rect.pos.y = top_Rect(bounds) + offset; |
563 | rect.size.y = docSize.y; | 549 | rect.size.y = docSize.y; |
564 | wasCentered = iTrue; | 550 | wasCentered = iTrue; |
@@ -594,9 +580,6 @@ static iInt2 documentPos_DocumentWidget_(const iDocumentWidget *d, iInt2 pos) { | |||
594 | } | 580 | } |
595 | 581 | ||
596 | static iRangei visibleRange_DocumentWidget_(const iDocumentWidget *d) { | 582 | static iRangei visibleRange_DocumentWidget_(const iDocumentWidget *d) { |
597 | // const int margin = -documentTopPad_DocumentWidget_(d) + | ||
598 | // d->pageMargin * gap_UI; | ||
599 | //const int top = -viewPos_DocumentWidget_(d) - margin; | ||
600 | int top = pos_SmoothScroll(&d->scrollY) - height_Banner(d->banner) - documentTopPad_DocumentWidget_(d); | 583 | int top = pos_SmoothScroll(&d->scrollY) - height_Banner(d->banner) - documentTopPad_DocumentWidget_(d); |
601 | if (isEmpty_Banner(d->banner)) { | 584 | if (isEmpty_Banner(d->banner)) { |
602 | /* Top padding is not collapsed. */ | 585 | /* Top padding is not collapsed. */ |
@@ -3939,6 +3922,9 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
3939 | if (processMediaEvents_DocumentWidget_(d, ev)) { | 3922 | if (processMediaEvents_DocumentWidget_(d, ev)) { |
3940 | return iTrue; | 3923 | return iTrue; |
3941 | } | 3924 | } |
3925 | if (processEvent_Banner(d->banner, ev)) { | ||
3926 | return iTrue; | ||
3927 | } | ||
3942 | /* The left mouse button. */ | 3928 | /* The left mouse button. */ |
3943 | switch (processEvent_Click(&d->click, ev)) { | 3929 | switch (processEvent_Click(&d->click, ev)) { |
3944 | case started_ClickResult: | 3930 | case started_ClickResult: |
@@ -4191,21 +4177,6 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
4191 | d->selectMark = iNullRange; | 4177 | d->selectMark = iNullRange; |
4192 | refresh_Widget(w); | 4178 | refresh_Widget(w); |
4193 | } | 4179 | } |
4194 | #if 0 | ||
4195 | /* Clicking on the top/side banner navigates to site root. */ | ||
4196 | const iRect banRect = siteBannerRect_DocumentWidget_(d); | ||
4197 | if (contains_Rect(banRect, pos_Click(&d->click))) { | ||
4198 | /* Clicking on a warning? */ | ||
4199 | if (bannerType_DocumentWidget_(d) == certificateWarning_GmDocumentBanner && | ||
4200 | pos_Click(&d->click).y - top_Rect(banRect) > | ||
4201 | lineHeight_Text(banner_FontId) * 2) { | ||
4202 | postCommand_Widget(d, "document.info"); | ||
4203 | } | ||
4204 | else { | ||
4205 | postCommand_Widget(d, "navigate.root"); | ||
4206 | } | ||
4207 | } | ||
4208 | #endif | ||
4209 | } | 4180 | } |
4210 | return iTrue; | 4181 | return iTrue; |
4211 | case aborted_ClickResult: | 4182 | case aborted_ClickResult: |