minibrowser: Disables urlbar when in fullscreen (#32425)

* minibrowser: Disables urlbar when in fullscreen

Signed-off-by: Nylme <nylme@protonmail.com>

* Added a TODO to minibrowser about: "Hiding URL bar in fullscreen is a phishing risk"

Signed-off-by: Nylme <nylme@protonmail.com>

* Ran ./mach fmt

Signed-off-by: Nylme <nylme@protonmail.com>

* Fixed typo.

Signed-off-by: Nylme <nylme@protonmail.com>

* Fixed `./mach tidy-test` failing for reason: "Line is longer than 120 characters" on a comment.
And deleted an unecessary comment.

Signed-off-by: Nylme <nylme@protonmail.com>

---------

Signed-off-by: Nylme <nylme@protonmail.com>
This commit is contained in:
Nylme 2024-06-12 08:53:56 +00:00 committed by GitHub
parent b4e41d8727
commit 699f6960f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -171,58 +171,64 @@ impl Minibrowser {
} = self; } = self;
let widget_fbo = *widget_surface_fbo; let widget_fbo = *widget_surface_fbo;
let _duration = context.run(window, |ctx| { let _duration = context.run(window, |ctx| {
TopBottomPanel::top("toolbar").show(ctx, |ui| { // TODO: While in fullscreen add some way to mitigate the increased phishing risk
ui.allocate_ui_with_layout( // when not displaying the URL bar: https://github.com/servo/servo/issues/32443
ui.available_size(), if !window.fullscreen().is_some() {
egui::Layout::left_to_right(egui::Align::Center), TopBottomPanel::top("toolbar").show(ctx, |ui| {
|ui| { ui.allocate_ui_with_layout(
if ui.button("back").clicked() { ui.available_size(),
event_queue.borrow_mut().push(MinibrowserEvent::Back); egui::Layout::left_to_right(egui::Align::Center),
} |ui| {
if ui.button("forward").clicked() { if ui.button("back").clicked() {
event_queue.borrow_mut().push(MinibrowserEvent::Forward); event_queue.borrow_mut().push(MinibrowserEvent::Back);
} }
ui.allocate_ui_with_layout( if ui.button("forward").clicked() {
ui.available_size(), event_queue.borrow_mut().push(MinibrowserEvent::Forward);
egui::Layout::right_to_left(egui::Align::Center), }
|ui| { ui.allocate_ui_with_layout(
if ui.button("go").clicked() { ui.available_size(),
event_queue.borrow_mut().push(MinibrowserEvent::Go); egui::Layout::right_to_left(egui::Align::Center),
location_dirty.set(false); |ui| {
} if ui.button("go").clicked() {
event_queue.borrow_mut().push(MinibrowserEvent::Go);
location_dirty.set(false);
}
match self.load_status { match self.load_status {
LoadStatus::LoadStart => { LoadStatus::LoadStart => {
ui.add(Spinner::new().color(Color32::GRAY)); ui.add(Spinner::new().color(Color32::GRAY));
}, },
LoadStatus::HeadParsed => { LoadStatus::HeadParsed => {
ui.add(Spinner::new().color(Color32::WHITE)); ui.add(Spinner::new().color(Color32::WHITE));
}, },
LoadStatus::LoadComplete => { /* No Spinner */ }, LoadStatus::LoadComplete => { /* No Spinner */ },
} }
let location_field = ui.add_sized( let location_field = ui.add_sized(
ui.available_size(), ui.available_size(),
egui::TextEdit::singleline(&mut *location.borrow_mut()), egui::TextEdit::singleline(&mut *location.borrow_mut()),
); );
if location_field.changed() { if location_field.changed() {
location_dirty.set(true); location_dirty.set(true);
} }
if ui.input(|i| i.clone().consume_key(Modifiers::COMMAND, Key::L)) { if ui.input(|i| {
location_field.request_focus(); i.clone().consume_key(Modifiers::COMMAND, Key::L)
} }) {
if location_field.lost_focus() && location_field.request_focus();
ui.input(|i| i.clone().key_pressed(Key::Enter)) }
{ if location_field.lost_focus() &&
event_queue.borrow_mut().push(MinibrowserEvent::Go); ui.input(|i| i.clone().key_pressed(Key::Enter))
location_dirty.set(false); {
} event_queue.borrow_mut().push(MinibrowserEvent::Go);
}, location_dirty.set(false);
); }
}, },
); );
}); },
);
});
};
// The toolbar height is where the Contexts available rect starts. // The toolbar height is where the Contexts available rect starts.
// For reasons that are unclear, the TopBottomPanels ui cursor exceeds this by one egui // For reasons that are unclear, the TopBottomPanels ui cursor exceeds this by one egui