mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-30 21:28:59 +00:00
UI/AppKit: Display query results on the find-in-page panel
This commit is contained in:
parent
40fcb00c14
commit
54183b8eef
Notes:
sideshowbarker
2024-07-16 21:34:08 +09:00
Author: https://github.com/trflynn89
Commit: 54183b8eef
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/135
5 changed files with 46 additions and 0 deletions
|
@ -37,6 +37,9 @@
|
|||
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap;
|
||||
- (void)onAudioPlayStateChange:(Web::HTML::AudioPlayState)play_state;
|
||||
|
||||
- (void)onFindInPageResult:(size_t)current_match_index
|
||||
totalMatchCount:(Optional<size_t> const&)total_match_count;
|
||||
|
||||
@end
|
||||
|
||||
@interface LadybirdWebView : NSClipView <NSMenuDelegate>
|
||||
|
|
|
@ -858,6 +858,11 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
|
|||
self.backgroundColor = Ladybird::gfx_color_to_ns_color(color);
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_find_in_page = [self](auto current_match_index, auto const& total_match_count) {
|
||||
[self.observer onFindInPageResult:current_match_index + 1
|
||||
totalMatchCount:total_match_count];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_insert_clipboard_entry = [](auto const& data, auto const&, auto const& mime_type) {
|
||||
NSPasteboardType pasteboard_type = nil;
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
|
||||
#import <System/Cocoa.h>
|
||||
|
||||
@interface SearchPanel : NSStackView
|
||||
|
@ -14,5 +16,7 @@
|
|||
- (void)findNextMatch:(id)selector;
|
||||
- (void)findPreviousMatch:(id)selector;
|
||||
- (void)useSelectionForFind:(id)selector;
|
||||
- (void)onFindInPageResult:(size_t)current_match_index
|
||||
totalMatchCount:(Optional<size_t> const&)total_match_count;
|
||||
|
||||
@end
|
||||
|
|
|
@ -25,6 +25,7 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
|||
|
||||
@property (nonatomic, strong) NSSearchField* search_field;
|
||||
@property (nonatomic, strong) NSButton* search_match_case;
|
||||
@property (nonatomic, strong) NSTextField* result_label;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -55,6 +56,9 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
|||
[self.search_match_case setState:NSControlStateValueOff];
|
||||
m_case_sensitivity = CaseSensitivity::CaseInsensitive;
|
||||
|
||||
self.result_label = [NSTextField labelWithString:@""];
|
||||
[self.result_label setHidden:YES];
|
||||
|
||||
auto* search_done = [NSButton buttonWithTitle:@"Done"
|
||||
target:self
|
||||
action:@selector(cancelSearch:)];
|
||||
|
@ -65,6 +69,7 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
|||
[self addView:search_previous inGravity:NSStackViewGravityLeading];
|
||||
[self addView:search_next inGravity:NSStackViewGravityLeading];
|
||||
[self addView:self.search_match_case inGravity:NSStackViewGravityLeading];
|
||||
[self addView:self.result_label inGravity:NSStackViewGravityLeading];
|
||||
[self addView:search_done inGravity:NSStackViewGravityTrailing];
|
||||
|
||||
[self setOrientation:NSUserInterfaceLayoutOrientationHorizontal];
|
||||
|
@ -120,6 +125,28 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)onFindInPageResult:(size_t)current_match_index
|
||||
totalMatchCount:(Optional<size_t> const&)total_match_count
|
||||
{
|
||||
if (total_match_count.has_value()) {
|
||||
auto* label_text = *total_match_count > 0
|
||||
? [NSString stringWithFormat:@"%zu of %zu matches", current_match_index, *total_match_count]
|
||||
: @"Phrase not found";
|
||||
|
||||
auto* label_attributes = @{
|
||||
NSFontAttributeName : [NSFont boldSystemFontOfSize:12.0f],
|
||||
};
|
||||
|
||||
auto* label_attribute = [[NSAttributedString alloc] initWithString:label_text
|
||||
attributes:label_attributes];
|
||||
|
||||
[self.result_label setAttributedStringValue:label_attribute];
|
||||
[self.result_label setHidden:NO];
|
||||
} else {
|
||||
[self.result_label setHidden:YES];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Private methods
|
||||
|
||||
- (Tab*)tab
|
||||
|
|
|
@ -385,6 +385,13 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)onFindInPageResult:(size_t)current_match_index
|
||||
totalMatchCount:(Optional<size_t> const&)total_match_count
|
||||
{
|
||||
[self.search_panel onFindInPageResult:current_match_index
|
||||
totalMatchCount:total_match_count];
|
||||
}
|
||||
|
||||
#pragma mark - NSWindow
|
||||
|
||||
- (void)setIsVisible:(BOOL)flag
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue