Skip to content

Commit

Permalink
Various updates:
Browse files Browse the repository at this point in the history
 * Add support for remote inspector, overhaul inspector API.

 * Fix issue with button height calculation in root stylesheet.

 * Enable window.performance API

 * Fix C API issue, allow ulPlatformSet___() calls to be performed at any point during runtime.
  • Loading branch information
adamjs committed Sep 1, 2022
1 parent eb77230 commit 3e70dc7
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ elseif (PORT MATCHES "UltralightWin")
endif ()
endif ()

set(ULTRALIGHTCORE_REV "f01ed448")
set(WEBCORE_REV "9058049a")
set(ULTRALIGHT_REV "92889541")
set(APPCORE_REV "f905014")
set(ULTRALIGHTCORE_REV "10841b49")
set(WEBCORE_REV "b3edb902")
set(ULTRALIGHT_REV "ebdd248e")
set(APPCORE_REV "0564064")

set(ULTRALIGHTCORE_DIR "${CMAKE_CURRENT_BINARY_DIR}/deps/UltralightCore/")
set(WEBCORE_DIR "${CMAKE_CURRENT_BINARY_DIR}/deps/WebCore/")
Expand Down
72 changes: 63 additions & 9 deletions samples/Sample 8 - Web Browser/src/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>
#include <string>

#define INSPECTOR_HEIGHT 400
#define INSPECTOR_DRAG_HANDLE_HEIGHT 10

Tab::Tab(UI* ui, uint64_t id, uint32_t width, uint32_t height, int x, int y)
: ui_(ui), id_(id), container_width_(width), container_height_(height) {
Expand Down Expand Up @@ -35,16 +35,56 @@ void Tab::Hide() {

void Tab::ToggleInspector() {
if (!inspector_overlay_) {
inspector_overlay_ = Overlay::Create(ui_->window_, view()->inspector(), 0, 0);
view()->CreateLocalInspectorView();
} else {
if (inspector_overlay_->is_hidden())
if (inspector_overlay_->is_hidden()) {
inspector_overlay_->Show();
else
} else {
inspector_overlay_->Hide();
}
}

// Force resize to update layout
Resize(container_width_, container_height_);
}


bool Tab::IsInspectorShowing() const {
if (!inspector_overlay_)
return false;

return !inspector_overlay_->is_hidden();
}

IntRect Tab::GetInspectorResizeDragHandle() const {
if (!IsInspectorShowing())
return IntRect::MakeEmpty();

int drag_handle_height_px = (uint32_t)std::round(INSPECTOR_DRAG_HANDLE_HEIGHT * ui_->window()->scale());

// This drag handle should span the width of the UI and be centered vertically at the boundary between
// the page overlay and inspector overlay.

int drag_handle_x = (int)inspector_overlay_->x();
int drag_handle_y = (int)inspector_overlay_->y() - drag_handle_height_px / 2;

return { drag_handle_x, drag_handle_y, drag_handle_x + (int)inspector_overlay_->width(),
drag_handle_y + drag_handle_height_px };
}

int Tab::GetInspectorHeight() const {
if (inspector_overlay_)
return inspector_overlay_->height();

return 0;
}

void Tab::SetInspectorHeight(int height) {
if (height > 2) {
inspector_overlay_->Resize(inspector_overlay_->width(), height);

// Trigger a resize to perform re-layout / re-size of content overlay
Resize(container_width_, container_height_);
}
}

void Tab::Resize(uint32_t width, uint32_t height) {
Expand All @@ -53,18 +93,18 @@ void Tab::Resize(uint32_t width, uint32_t height) {

uint32_t content_height = container_height_;
if (inspector_overlay_ && !inspector_overlay_->is_hidden()) {
uint32_t inspector_height_px = (uint32_t)std::round(INSPECTOR_HEIGHT * ui_->window_->scale());
inspector_overlay_->Resize(container_width_, inspector_height_px);
content_height -= inspector_height_px;
content_height -= inspector_overlay_->height();
}

if (content_height < 1)
content_height = 1;

overlay_->Resize(container_width_, content_height);

if (inspector_overlay_ && !inspector_overlay_->is_hidden())
if (inspector_overlay_ && !inspector_overlay_->is_hidden()) {
inspector_overlay_->MoveTo(0, overlay_->y() + overlay_->height());
inspector_overlay_->Resize(container_width_, inspector_overlay_->height());
}
}

void Tab::OnChangeTitle(View* caller, const String& title) {
Expand Down Expand Up @@ -97,6 +137,20 @@ RefPtr<View> Tab::OnCreateChildView(ultralight::View* caller,
return ui_->CreateNewTabForChildView(target_url);
}

RefPtr<View> Tab::OnCreateInspectorView(ultralight::View* caller, bool is_local,
const String& inspected_url) {
if (inspector_overlay_)
return nullptr;

inspector_overlay_ = Overlay::Create(ui_->window_, container_width_, container_height_ / 2, 0, 0);

// Force resize to update layout
Resize(container_width_, container_height_);
inspector_overlay_->Show();

return inspector_overlay_->view();
}

void Tab::OnBeginLoading(View* caller, uint64_t frame_id, bool is_main_frame, const String& url) {
ui_->UpdateTabNavigation(id_, caller->is_loading(), caller->CanGoBack(), caller->CanGoForward());
}
Expand Down
10 changes: 10 additions & 0 deletions samples/Sample 8 - Web Browser/src/Tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class Tab : public ViewListener,
void Hide();

void ToggleInspector();

bool IsInspectorShowing() const;

IntRect GetInspectorResizeDragHandle() const;

int GetInspectorHeight() const;

void SetInspectorHeight(int height);

void Resize(uint32_t width, uint32_t height);

Expand All @@ -38,6 +46,8 @@ class Tab : public ViewListener,
virtual RefPtr<View> OnCreateChildView(ultralight::View* caller,
const String& opener_url, const String& target_url,
bool is_popup, const IntRect& popup_rect) override;
virtual RefPtr<View> OnCreateInspectorView(ultralight::View* caller, bool is_local,
const String& inspected_url) override;

// Inherited from Listener::Load
virtual void OnBeginLoading(View* caller, uint64_t frame_id,
Expand Down
51 changes: 49 additions & 2 deletions samples/Sample 8 - Web Browser/src/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ static UI* g_ui = 0;

#define UI_HEIGHT 80

UI::UI(RefPtr<Window> window) : window_(window) {
UI::UI(RefPtr<Window> window) : window_(window), cur_cursor_(Cursor::kCursor_Pointer),
is_resizing_inspector_(false), is_over_inspector_resize_drag_handle_(false) {
uint32_t window_width = window_->width();
ui_height_ = (uint32_t)std::round(UI_HEIGHT * window_->scale());
overlay_ = Overlay::Create(window_, window_width, ui_height_, 0, 0);
Expand All @@ -21,6 +22,53 @@ UI::~UI() {
g_ui = nullptr;
}

bool UI::OnKeyEvent(const ultralight::KeyEvent& evt) {
return true;
}

bool UI::OnMouseEvent(const ultralight::MouseEvent& evt) {
if (active_tab() && active_tab()->IsInspectorShowing()) {
float x_px = std::round(evt.x * window()->scale());
float y_px = std::round(evt.y * window()->scale());

if (is_resizing_inspector_) {
int resize_delta = inspector_resize_begin_mouse_y_ - y_px;
int new_inspector_height = inspector_resize_begin_height_ + resize_delta;
active_tab()->SetInspectorHeight(new_inspector_height);

if (evt.type == MouseEvent::kType_MouseUp) {
is_resizing_inspector_ = false;
}

return false;
}

IntRect drag_handle = active_tab()->GetInspectorResizeDragHandle();

bool over_drag_handle = drag_handle.Contains(Point(x_px, y_px));

if (over_drag_handle && !is_over_inspector_resize_drag_handle_) {
// We entered the drag area
window()->SetCursor(Cursor::kCursor_NorthSouthResize);
is_over_inspector_resize_drag_handle_ = true;
} else if (!over_drag_handle && is_over_inspector_resize_drag_handle_) {
// We left the drag area, restore previous cursor
window()->SetCursor(cur_cursor_);
is_over_inspector_resize_drag_handle_ = false;
}

if (over_drag_handle && evt.type == MouseEvent::kType_MouseDown && !is_resizing_inspector_) {
is_resizing_inspector_ = true;
inspector_resize_begin_mouse_y_ = y_px;
inspector_resize_begin_height_ = active_tab()->GetInspectorHeight();
}

return !over_drag_handle;
}

return true;
}

void UI::OnClose(ultralight::Window* window) {
App::instance()->Quit();
}
Expand Down Expand Up @@ -186,7 +234,6 @@ RefPtr<View> UI::CreateNewTabForChildView(const String& url) {
return tabs_[id]->view();
}


void UI::UpdateTabTitle(uint64_t id, const ultralight::String& title) {
RefPtr<JSContext> lock(view()->LockJSContext());
updateTab({ id, title, "", tabs_[id]->view()->is_loading() });
Expand Down
8 changes: 8 additions & 0 deletions samples/Sample 8 - Web Browser/src/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class UI : public WindowListener,
~UI();

// Inherited from WindowListener
virtual bool OnKeyEvent(const ultralight::KeyEvent& evt) override;
virtual bool OnMouseEvent(const ultralight::MouseEvent& evt) override;
virtual void OnClose(ultralight::Window* window) override;
virtual void OnResize(ultralight::Window* window, uint32_t width, uint32_t height) override;

Expand All @@ -43,6 +45,8 @@ class UI : public WindowListener,
void OnActiveTabChange(const JSObject& obj, const JSArgs& args);
void OnRequestChangeURL(const JSObject& obj, const JSArgs& args);

RefPtr<Window> window() { return window_; }

protected:
void CreateNewTab();
RefPtr<View> CreateNewTabForChildView(const String& url);
Expand Down Expand Up @@ -70,6 +74,10 @@ class UI : public WindowListener,
uint64_t active_tab_id_ = 0;
uint64_t tab_id_counter_ = 0;
Cursor cur_cursor_;
bool is_resizing_inspector_;
bool is_over_inspector_resize_drag_handle_;
int inspector_resize_begin_height_;
int inspector_resize_begin_mouse_y_;

JSFunction updateBack;
JSFunction updateForward;
Expand Down

0 comments on commit 3e70dc7

Please sign in to comment.