summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorSven Weidauer <sven@5sw.de>2017-12-27 21:33:16 +0100
committerSven Weidauer <sven@5sw.de>2017-12-27 21:33:16 +0100
commit4f7885e277eb53af1662c507c145767d699056bf (patch)
treef5e7e99ce241d08f1cba76409ff4934ce5d78f82 /frontends
parentf035d6dbeb398cbb64df75f2ad400624b26efb5f (diff)
downloadnetsurf-4f7885e277eb53af1662c507c145767d699056bf.tar.gz
netsurf-4f7885e277eb53af1662c507c145767d699056bf.tar.bz2
Fix position of caret when zooming content.
Diffstat (limited to 'frontends')
-rw-r--r--frontends/cocoa/BrowserView.h4
-rw-r--r--frontends/cocoa/BrowserView.m33
-rw-r--r--frontends/cocoa/gui.m4
3 files changed, 13 insertions, 28 deletions
diff --git a/frontends/cocoa/BrowserView.h b/frontends/cocoa/BrowserView.h
index 596100f09..cf1b0dc02 100644
--- a/frontends/cocoa/BrowserView.h
+++ b/frontends/cocoa/BrowserView.h
@@ -25,8 +25,6 @@
@interface BrowserView : ScrollableView <NSTextInput> {
struct browser_window *browser;
- NSPoint caretPoint;
- CGFloat caretHeight;
BOOL caretVisible;
BOOL hasCaret;
NSTimer *caretTimer;
@@ -45,7 +43,7 @@
@property (readwrite, assign, nonatomic, getter=isHistoryVisible) BOOL historyVisible;
- (void)removeCaret;
-- (void)addCaretAt:(NSPoint)point height:(CGFloat)height;
+- (void)addCaretAtX: (int)caretX Y: (int)caretY height: (int)caretHeight;
- (void)updateHistory;
diff --git a/frontends/cocoa/BrowserView.m b/frontends/cocoa/BrowserView.m
index c1cf9beb9..31d433515 100644
--- a/frontends/cocoa/BrowserView.m
+++ b/frontends/cocoa/BrowserView.m
@@ -38,6 +38,8 @@
@property (readwrite, copy, nonatomic) NSString *markedText;
+@property (readwrite, nonatomic) NSRect caretRect;
+
- (void)scrollHorizontal:(CGFloat)amount;
- (void)scrollVertical:(CGFloat)amount;
- (CGFloat)pageScroll;
@@ -92,34 +94,22 @@ static const NSTimeInterval CaretBlinkTime = 0.8;
[history redraw];
}
-static inline NSRect cocoa_get_caret_rect(BrowserView *view)
-{
- float bscale = browser_window_get_scale(view->browser);
-
- NSRect caretRect = {
- .origin = NSMakePoint(view->caretPoint.x * bscale, view->caretPoint.y * bscale),
- .size = NSMakeSize(CaretWidth, view->caretHeight * bscale)
- };
-
- return caretRect;
-}
-
- (void)removeCaret
{
hasCaret = NO;
- [self setNeedsDisplayInRect:cocoa_get_caret_rect(self)];
+ [self setNeedsDisplayInRect: self.caretRect];
[self setCaretTimer:nil];
}
-- (void)addCaretAt:(NSPoint)point height:(CGFloat)height
+- (void)addCaretAtX: (int)caretX Y: (int)caretY height: (int)caretHeight;
{
if (hasCaret) {
- [self setNeedsDisplayInRect:cocoa_get_caret_rect(self)];
+ [self setNeedsDisplayInRect:self.caretRect];
}
- caretPoint = point;
- caretHeight = height;
+ self.caretRect = cocoa_rect_wh(caretX, caretY, CaretWidth, caretHeight);
+
hasCaret = YES;
caretVisible = YES;
@@ -129,14 +119,14 @@ static inline NSRect cocoa_get_caret_rect(BrowserView *view)
[caretTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:CaretBlinkTime]];
}
- [self setNeedsDisplayInRect:cocoa_get_caret_rect(self)];
+ [self setNeedsDisplayInRect:self.caretRect];
}
- (void)caretBlink:(NSTimer *)timer
{
if (hasCaret) {
caretVisible = !caretVisible;
- [self setNeedsDisplayInRect:cocoa_get_caret_rect(self)];
+ [self setNeedsDisplayInRect: self.caretRect];
}
}
@@ -165,10 +155,9 @@ static inline NSRect cocoa_get_caret_rect(BrowserView *view)
browser_window_redraw(browser, 0, 0, &clip, &ctx);
}
- NSRect caretRect = cocoa_get_caret_rect(self);
- if (hasCaret && caretVisible && [self needsToDrawRect:caretRect]) {
+ if (hasCaret && caretVisible && [self needsToDrawRect:self.caretRect]) {
[[NSColor blackColor] set];
- [NSBezierPath fillRect:caretRect];
+ [NSBezierPath fillRect: self.caretRect];
}
}
}
diff --git a/frontends/cocoa/gui.m b/frontends/cocoa/gui.m
index f564563f8..599c3b49e 100644
--- a/frontends/cocoa/gui.m
+++ b/frontends/cocoa/gui.m
@@ -253,9 +253,7 @@ static void
gui_window_place_caret(struct gui_window *g, int x, int y, int height,
const struct rect *clip)
{
- [[(__bridge BrowserViewController *)g browserView]
- addCaretAt:cocoa_point(x, y)
- height:cocoa_px_to_pt(height)];
+ [[(__bridge BrowserViewController *)g browserView] addCaretAtX:x Y:y height:height];
}
static void gui_window_remove_caret(struct gui_window *g)