Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Jan 9, 2024
1 parent 8132c04 commit cd8bd91
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
36 changes: 25 additions & 11 deletions src/WinWebDiffLib/DiffLocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class DiffLocation
}
m_diffRects[pane].insert_or_assign(window, diffRects);
m_containerRects[pane].insert_or_assign(window, containerRects);
if (window == L"")
{
m_scrollX[pane] = doc[L"scrollX"].GetFloat();
m_scrollY[pane] = doc[L"scrollY"].GetFloat();
m_innerWidth[pane] = doc[L"innerWidth"].GetFloat();
m_innerHeight[pane] = doc[L"innerHeight"].GetFloat();
}
}

void clear()
Expand All @@ -54,6 +61,11 @@ class DiffLocation
m_diffRects[pane].clear();
m_containerRects[pane].clear();
m_diffRectsSerialized[pane].clear();
m_containerRectsSerialized[pane].clear();
m_scrollX[pane] = 0.0f;
m_scrollY[pane] = 0.0f;
m_innerWidth[pane] = 0.0f;
m_innerHeight[pane] = 0.0f;
}
}

Expand All @@ -65,12 +77,11 @@ class DiffLocation
const auto& key = pair.first;
for (const auto& diffRect : pair.second)
{
const auto& containerRect = m_containerRects[pane][key][diffRect.containerId];
IWebDiffWindow::DiffRect rect;
rect.id = diffRect.id;
rect.containerId = diffRect.containerId;
rect.left = diffRect.left + containerRect.scrollLeft;
rect.top = diffRect.top + containerRect.scrollTop;
rect.left = diffRect.left + m_scrollX[pane];
rect.top = diffRect.top + m_scrollY[pane];
rect.width = diffRect.width;
rect.height = diffRect.height;
m_diffRectsSerialized[pane].push_back(rect);
Expand All @@ -91,14 +102,8 @@ class DiffLocation
IWebDiffWindow::ContainerRect rect;
rect.id = containerRect.id;
rect.containerId = containerRect.containerId;
rect.left = containerRect.left;
rect.top = containerRect.top;
if (containerRect.containerId != -1)
{
const auto& containerContainerRect = m_containerRects[pane][key][containerRect.containerId];
rect.left += containerContainerRect.scrollLeft;
rect.top += containerContainerRect.scrollTop;
}
rect.left = containerRect.left + m_scrollX[pane];
rect.top = containerRect.top + m_scrollY[pane];
rect.width = containerRect.width;
rect.height = containerRect.height;
rect.scrollLeft = containerRect.scrollLeft;
Expand All @@ -114,8 +119,17 @@ class DiffLocation
return m_containerRectsSerialized[pane].data();
}

IWebDiffWindow::Rect GetVisibleAreaRect(int pane)
{
return { m_scrollX[pane], m_scrollY[pane], m_innerWidth[pane], m_innerHeight[pane] };
}

std::map<std::wstring, std::vector<IWebDiffWindow::DiffRect>> m_diffRects[3];
std::map<std::wstring, std::vector<IWebDiffWindow::ContainerRect>> m_containerRects[3];
std::vector<IWebDiffWindow::DiffRect> m_diffRectsSerialized[3];
std::vector<IWebDiffWindow::ContainerRect> m_containerRectsSerialized[3];
float m_scrollX[3] = { 0.0f, 0.0f, 0.0f };
float m_scrollY[3] = { 0.0f, 0.0f, 0.0f };
float m_innerWidth[3] = { 0.0f, 0.0f, 0.0f };
float m_innerHeight[3] = { 0.0f, 0.0f, 0.0f };
};
5 changes: 5 additions & 0 deletions src/WinWebDiffLib/WebDiffWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,11 @@ class CWebDiffWindow : public IWebDiffWindow
return m_diffLocation.GetContainerRectArray(pane, count);
}

Rect GetVisibleAreaRect(int pane) override
{
return m_diffLocation.GetVisibleAreaRect(pane);
}

private:

HRESULT getDocumentsLoop(std::shared_ptr<std::vector<std::wstring>> jsons, IWebDiffCallback* callback, int pane = 0)
Expand Down
10 changes: 6 additions & 4 deletions src/WinWebDiffLib/WebToolWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,12 @@ class CWebToolWindow : public IWebToolWindow, IWebDiffEventHandler
if (containerCounts[pane] > 0)
{
RECT rcContainer = getContainerRect(pane, 0);
rcContainer.left += static_cast<int>(containerRects[pane][0].scrollLeft * ratiox);
rcContainer.right = static_cast<int>(rcContainer.left + containerRects[pane][0].clientWidth * ratiox);
rcContainer.top += static_cast<int>(containerRects[pane][0].scrollTop * ratioy);
rcContainer.bottom = static_cast<int>(rcContainer.top + containerRects[pane][0].clientHeight * ratioy);
auto visibleArea = m_pWebDiffWindow->GetVisibleAreaRect(pane);

rcContainer.left += static_cast<int>(visibleArea.left * ratiox);
rcContainer.right = static_cast<int>(rcContainer.left + visibleArea.width * ratiox);
rcContainer.top += static_cast<int>(visibleArea.top * ratioy);
rcContainer.bottom = static_cast<int>(rcContainer.top + visibleArea.height * ratioy);
Rectangle(pDrawItem->hDC, rcContainer.left, rcContainer.top, rcContainer.right, rcContainer.bottom);
}

Expand Down
7 changes: 5 additions & 2 deletions src/WinWebDiffLib/WinWebDiffLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ struct IWebDiffWindow

struct Rect
{
int id;
int containerId;
float left;
float top;
float width;
float height;
};
struct ContainerRect : public Rect
{
int id;
int containerId;
float scrollLeft;
float scrollTop;
float scrollWidth;
Expand All @@ -135,6 +135,8 @@ struct IWebDiffWindow
};
struct DiffRect : public Rect
{
int id;
int containerId;
};

virtual bool IsWebView2Installed() const = 0;
Expand Down Expand Up @@ -216,6 +218,7 @@ struct IWebDiffWindow
virtual void RaiseEvent(const WebDiffEvent& e) = 0;
virtual const DiffRect* GetDiffRectArray(int pane, int& count) = 0;
virtual const ContainerRect* GetContainerRectArray(int pane, int& count) = 0;
virtual Rect GetVisibleAreaRect(int pane) = 0;
};

struct IWebToolWindow
Expand Down
Binary file modified src/WinWebDiffLib/WinWebDiffLib.js
Binary file not shown.

0 comments on commit cd8bd91

Please sign in to comment.