Skip to content

Commit

Permalink
Ladybird: Ensure hamburger menu is placed within the browser window
Browse files Browse the repository at this point in the history
  • Loading branch information
MacDue authored and awesomekling committed May 8, 2024
1 parent e10721f commit 563d392
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Ladybird/Qt/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ static QIcon const& app_icon()
return icon;
}

class HamburgerMenu : public QMenu {
public:
using QMenu::QMenu;
virtual ~HamburgerMenu() override = default;

virtual void showEvent(QShowEvent*) override
{
if (!isVisible())
return;
auto* browser_window = verify_cast<BrowserWindow>(parentWidget());
if (!browser_window)
return;
auto* current_tab = browser_window->current_tab();
if (!current_tab)
return;
// Ensure the hamburger menu placed within the browser window.
auto* hamburger_button = current_tab->hamburger_button();
auto button_top_right = hamburger_button->mapToGlobal(hamburger_button->rect().bottomRight());
move(button_top_right - QPoint(rect().width(), 0));
}
};

BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path)
: m_tabs_container(new TabWidget(this))
, m_cookie_jar(cookie_jar)
Expand All @@ -72,7 +94,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
});
}

m_hamburger_menu = new QMenu(this);
m_hamburger_menu = new HamburgerMenu(this);

if (!Settings::the()->show_menubar())
menuBar()->hide();
Expand Down
2 changes: 2 additions & 0 deletions Ladybird/Qt/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class BrowserWindow : public QMainWindow {
return *m_inspect_dom_node_action;
}

Tab* current_tab() const { return m_current_tab; }

public slots:
void device_pixel_ratio_changed(qreal dpi);
void tab_title_changed(int index, QString const&);
Expand Down
2 changes: 2 additions & 0 deletions Ladybird/Qt/Tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Tab final : public QWidget {

void update_navigation_buttons_state();

QToolButton* hamburger_button() const { return m_hamburger_button; }

public slots:
void focus_location_editor();
void location_edit_return_pressed();
Expand Down

0 comments on commit 563d392

Please sign in to comment.