Truly independent web browser
UI/Qt: Lift the omnibox on hover like the toolbar buttons
Andreas Kling9c0e0094e5ac
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cppindex 9c009c70e36..863af5a1113 100644--- a/UI/Qt/ChromeStyle.cpp+++ b/UI/Qt/ChromeStyle.cpp@@ -594,6 +594,12 @@ static QColor autocomplete_surface(QPalette const& palette)return chrome_surface(palette);}+// Hovering a frameless control only lifts it with this soft fill; its ring appears once it is pressed.+static QColor chrome_control_soft_hover(QPalette const& palette)+{+ return is_dark(palette) ? QColor(255, 255, 255, 24) : QColor(0, 0, 0, 16);+}+static QColor location_edit_focus_border(QPalette const& palette){return mix(chrome_border(palette), chrome_accent(), is_dark(palette) ? 0.50 : 0.54);@@ -605,7 +611,9 @@ QString location_edit_style_sheet(QPalette const& palette)auto surface_color = chrome_surface(palette);if (dark)surface_color = mix(chrome_background(palette), material_color_anchors(true).background, 0.34);- auto hover_color = surface_color;+ // Hovering the field lifts it with the same soft fill as the toolbar buttons, to show that it can be clicked.+ auto soft_hover = chrome_control_soft_hover(palette);+ auto hover_color = mix(surface_color, QColor(soft_hover.rgb()), soft_hover.alpha() / 255.0);auto focus_color = dark ? mix(surface_color, QColor(255, 255, 255), 0.035) : surface_color;auto border_color = dark ? mix(chrome_background(palette), chrome_border(palette), 0.36) : chrome_border(palette);@@ -647,7 +655,7 @@ QLineEdit#LadybirdLocationEdit {{placeholder-text-color: {5};}}-QLineEdit#LadybirdLocationEdit:hover {{+QLineEdit#LadybirdLocationEdit[fieldHovered="true"] {{background: {1};border-color: {8};}}@@ -721,12 +729,6 @@ QToolButton#LadybirdLocationAction {{not_secure_text, not_secure_background, not_secure_hover, not_secure_pressed, not_secure_border, zoom_text, zoom_background, zoom_hover, zoom_pressed, zoom_border, focus, LOCATION_EDIT_CORNER_RADIUS, popup_surface);}-// Hovering a frameless control only lifts it with this soft fill; its ring appears once it is pressed.-static QColor chrome_control_soft_hover(QPalette const& palette)-{- return is_dark(palette) ? QColor(255, 255, 255, 24) : QColor(0, 0, 0, 16);-}-QString bookmarks_bar_style_sheet(QPalette const& palette, int corner_radius){auto hover = style_sheet_color_with_alpha(chrome_control_soft_hover(palette));diff --git a/UI/Qt/LocationEdit.cpp b/UI/Qt/LocationEdit.cppindex 51505a06c10..8c872590cb3 100644--- a/UI/Qt/LocationEdit.cpp+++ b/UI/Qt/LocationEdit.cpp@@ -152,6 +152,9 @@ LocationEdit::LocationEdit(QWidget* parent, WebView::IsPrivate is_private)m_zoom_action->trigger();});+ for (auto* button : { m_leading_icon_button, m_trailing_action_button, m_zoom_indicator_button })+ button->installEventFilter(this);+update_text_margins();update_placeholder();update_location_icon();@@ -291,11 +294,47 @@ void LocationEdit::show_autocomplete()void LocationEdit::changeEvent(QEvent* event){QLineEdit::changeEvent(event);+ // NB: Repolishing for the hover look changes our palette to the hovered colors, which needs no new style.+ if (event->type() == QEvent::PaletteChange && m_is_updating_field_hover)+ return;if (event->type() == QEvent::PaletteChange || event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange) {schedule_chrome_style_update();}}+bool LocationEdit::event(QEvent* event)+{+ if (event->type() == QEvent::Enter)+ set_field_hovered(true);+ else if (event->type() == QEvent::Leave)+ set_field_hovered(false);+ return QLineEdit::event(event);+}++bool LocationEdit::eventFilter(QObject* watched, QEvent* event)+{+ // The buttons inside the field have their own hover look, so the field itself does not look hovered under them.+ if (event->type() == QEvent::Enter)+ set_field_hovered(false);+ else if (event->type() == QEvent::Leave)+ set_field_hovered(underMouse());+ return QLineEdit::eventFilter(watched, event);+}++// NB: The style sheet's :hover would also match while the mouse is over one of the buttons inside the field, so the+// field's hover look follows this property instead.+void LocationEdit::set_field_hovered(bool hovered)+{+ if (property("fieldHovered").toBool() == hovered)+ return;+ setProperty("fieldHovered", hovered);+ m_is_updating_field_hover = true;+ style()->unpolish(this);+ style()->polish(this);+ m_is_updating_field_hover = false;+ update();+}+void LocationEdit::contextMenuEvent(QContextMenuEvent* event){QMenu* menu = createStandardContextMenu();diff --git a/UI/Qt/LocationEdit.h b/UI/Qt/LocationEdit.hindex 31693f650c4..242ac393255 100644--- a/UI/Qt/LocationEdit.h+++ b/UI/Qt/LocationEdit.h@@ -55,6 +55,8 @@ signals:private:virtual void changeEvent(QEvent* event) override;+ virtual bool event(QEvent* event) override;+ virtual bool eventFilter(QObject* watched, QEvent* event) override;virtual void contextMenuEvent(QContextMenuEvent* event) override;virtual void focusInEvent(QFocusEvent* event) override;virtual void focusOutEvent(QFocusEvent* event) override;@@ -75,6 +77,7 @@ private:void update_location_icon();void update_zoom_indicator();void update_focus_glow(int alpha);+ void set_field_hovered(bool);void schedule_chrome_style_update();void animate_focus_glow(int target_alpha);void highlight_location();@@ -97,6 +100,7 @@ private:bool m_url_is_hidden { false };bool m_has_user_edited_hidden_url { false };bool m_is_updating_chrome_style { false };+ bool m_is_updating_field_hover { false };bool m_has_pending_chrome_style_update { false };bool m_should_show_full_url_on_mouse_release { false };int m_text_leading_margin { 0 };