Save scroll position in sessions

master
boisso 8 years ago
parent c9094de291
commit 9dbc0ca642
  1. 5
      k-meleon/BrowserFrm.h
  2. 6
      k-meleon/BrowserGlue.cpp
  3. 50
      k-meleon/BrowserWindow.cpp
  4. 24
      k-meleon/BrowserWindow.h
  5. 20
      k-meleon/Plugins.cpp
  6. 1
      k-meleon/sessions/sessions.cpp
  7. 15
      k-meleon/sessions/sessions.h
  8. 6
      k-meleon/sessions/sessionstore.cpp

@ -66,7 +66,9 @@ public:
BOOL mDOMLoaded;
int mProgressCurrent;
int mProgressMax;
CPoint mScroll;
bool firstLoad;
nsCOMPtr<nsIURI> mIconURI;
nsCOMPtr<nsIDOMNode> mContextNode;
@ -80,7 +82,8 @@ public:
mpBrowserFrame(frame),
mpBrowserView(view),
firstLoad(true),
mHIndex(-1)
mHIndex(-1),
mScroll(0,0)
{
}

@ -75,7 +75,11 @@ void CBrowserGlue::UpdateBusyState(BOOL aBusy)
}
else {
SetFavIcon(nullptr);
mPendingLocation = _T("");
mPendingLocation = _T("");
if (mScroll.x || mScroll.y) {
mpBrowserView->GetBrowserWrapper()->SetScrollPosition(mScroll);
mScroll.x = mScroll.y = 0;
}
/*
nsCOMPtr<nsIDOMEventTarget> eventTarget;
nsCOMPtr<nsIWebBrowser> br = mpBrowserView->GetBrowserWrapper()->GetWebBrowser();

@ -826,46 +826,36 @@ BOOL CBrowserWrapper::InitPrintSettings()
nsresult rv = psService->InitPrintSettingsFromPrefs(mPrintSettings, PR_FALSE, nsIPrintSettings::kInitSaveAll);
return NS_SUCCEEDED(rv);
}
//#include "BrowserFrm.h"
//#include "BrowserView.h"
#include "BrowserFrm.h"
#include "BrowserView.h"
BOOL CBrowserWrapper::PrintPreview()
{
nsCOMPtr<nsIWebBrowserPrint> print;
nsIDocShell* shell = GetDocShell();
shell->GetPrintPreview(getter_AddRefs(print));
if (!print) return FALSE;
nsIDocShell* shell;
if (!mPrintSettings) InitPrintSettings();
bool isPreview = false;
nsresult rv = print->GetDoingPrintPreview(&isPreview);
nsCOMPtr<nsIDOMWindow> dom;
nsresult rv = mWebBrowser->GetContentDOMWindow(getter_AddRefs(dom));
NS_ENSURE_SUCCESS(rv, FALSE);
if (isPreview)
rv = print->ExitPrintPreview();
else {
nsCOMPtr<nsIDOMWindow> dom;
rv = mWebBrowser->GetContentDOMWindow(getter_AddRefs(dom));
NS_ENSURE_SUCCESS(rv, FALSE);
CBrowserFrame* frm = theApp.CreateNewBrowserFrame(nsIWebBrowserChrome::CHROME_DEFAULT, false, CWnd::FromHandle(mpBrowserGlue->GetBrowserFrameNativeWnd()));
shell = frm->GetActiveView()->GetBrowserWrapper()->GetDocShell();
shell->GetPrintPreview(getter_AddRefs(print));
if (!print) {
frm->DestroyWindow();
return FALSE;
}
frm->ShowWindow(SW_SHOW);
rv = print->PrintPreview(mPrintSettings, dom, nullptr);
/* CBrowserFrame* frm = theApp.CreateNewBrowserFrameWithUrl(L"about:blank");//nsIWebBrowserChrome::CHROME_OPENAS_CHROME | nsIWebBrowserChrome::CHROME_DEFAULT);
shell = frm->GetActiveView()->GetBrowserWrapper()->GetDocShell();
shell->GetPrintPreview(getter_AddRefs(print));
if (!print) return FALSE;
frm->ShowWindow(SW_SHOW);
uint32_t flags;
mpBrowserImpl->GetChromeFlags(&flags);
this->CreateBrowser(mWndOwner, flags);*/
rv = print->PrintPreview(mPrintSettings, dom, nullptr);
// WORKAROUND - FIX ME: Why the print preview doesn't use all the width?
// So I'm forcing the window to reposition itself.
//CRect rect;
//mWndOwner->GetClientRect(rect);
//mBaseWindow->SetPositionAndSize(0, 0, rect.right, rect.bottom, PR_TRUE);
// WORKAROUND - FIX ME: Why the print preview doesn't use all the width?
// So I'm forcing the window to reposition itself.
//CRect rect;
//mWndOwner->GetClientRect(rect);
//mBaseWindow->SetPositionAndSize(0, 0, rect.right, rect.bottom, PR_TRUE);
}
return NS_SUCCEEDED(rv);
}

@ -85,6 +85,29 @@ public:
void GoForward() { if (mWebNav) mWebNav->GoForward(); }
void Stop() { if(mWebNav) mWebNav->Stop(nsIWebNavigation::STOP_ALL); }
bool SetScrollPosition(POINT scroll)
{
nsCOMPtr<nsIDOMWindow> dom;
if (mWebBrowser) mWebBrowser->GetContentDOMWindow(getter_AddRefs(dom));
if (!dom) return false;
return NS_SUCCEEDED(dom->ScrollTo(scroll.x, scroll.y));
}
POINT GetScrollPosition()
{
POINT p = {0,0};
nsCOMPtr<nsIDOMWindow> dom;
if (mWebBrowser) mWebBrowser->GetContentDOMWindow(getter_AddRefs(dom));
if (dom) {
int32_t s = 0;
dom->GetScrollX(&s);
p.x = s;
dom->GetScrollY(&s);
p.y = s;
}
return p;
}
BOOL AllowJS(BOOL allow)
{
nsCOMPtr<nsIDocShell> ds = GetDocShell();
@ -366,7 +389,6 @@ public:
#endif
//BOOL FindNext(BOOL backward);*/
private:
BOOL AddListeners(void);
void RemoveListeners(void);

@ -373,6 +373,9 @@ kmeleonDocInfo * GetDocInfoUTF8(HWND mainWnd)
}
#endif
POINT scroll = browser->GetScrollPosition();
kDocInfo.scrollX = scroll.x;
kDocInfo.scrollY = scroll.y;
return &kDocInfo;
}
@ -399,6 +402,9 @@ kmeleonDocInfo * GetDocInfo(HWND mainWnd)
kDocInfo.idxIcon = theApp.favicons.GetIcon(view->GetBrowserGlue()->mIconURI);
#endif
POINT scroll = browser->GetScrollPosition();
kDocInfo.scrollX = scroll.x;
kDocInfo.scrollY = scroll.y;
return &kDocInfo;
}
@ -492,7 +498,7 @@ void SetStatusBarText(const char *s)
#include "nsISHistoryInternal.h"
#include "MozUtils.h"
int SetMozillaSessionHistory (HWND hWnd, const char **titles, const char **urls, int count, int index)
int SetMozillaSessionHistory (HWND hWnd, const char **titles, const char **urls, int count, int index, int scrollX, int scrollY)
{
PLUGIN_HEADER(hWnd, 0);
nsresult rv;
@ -526,6 +532,8 @@ int SetMozillaSessionHistory (HWND hWnd, const char **titles, const char **urls,
if (NS_SUCCEEDED(rv)) sHInternal->AddEntry(newSHEntry, PR_TRUE);
}
view->GetBrowserGlue()->mScroll.x = scrollX;
view->GetBrowserGlue()->mScroll.y = scrollY;
if (frame->IsKindOf(RUNTIME_CLASS(CBrowserFrmTab)) && theApp.preferences.GetBool("browser.sessionstore.restore_on_demand", false)) {
if (index>=count) index = count - 1;
if (index<0) index = 0;
@ -1728,14 +1736,16 @@ void ReleaseCmdID(UINT id)
UINT RegisterCmd(const char* name, const char* desc, const char* icon)
{
USES_CONVERSION;
return theApp.commands.RegisterCommand(A2CT(name), A2CT(desc), A2CT(icon));
if (!name || !desc) return 0;
USES_CONVERSION;
return theApp.commands.RegisterCommand(A2CT(name), A2CT(desc), icon?A2CT(icon):nullptr);
}
void UnregisterCmd(const char* cmd, const char* plugin)
void UnregisterCmd(const char* cmd)
{
if (!cmd) return;
USES_CONVERSION;
return theApp.commands.UnregisterCommand(A2CT(plugin), A2CT(cmd));
return theApp.commands.UnregisterCommand(A2CT(cmd));
}
unsigned GetCmdList(kmeleonCommand* cmdList, unsigned size)

@ -174,6 +174,7 @@ long DoMessage(const char *to, const char *from, const char *subject, long data1
}
else if (strcmp(subject, "SwitchTab") == 0) {
int selected = 0;
if (!data1) return 0;
Window* w = currentSession.getWindow(GetParent((HWND)data1));
if (w) {
kPlugin.kFuncs->GetWindowVar((HWND)data1, Window_Tab_Index, &selected);

@ -41,6 +41,8 @@ class Tab {
int shcount;
int index;
int scrollX;
int scrollY;
std::vector<std::string> titles;
std::vector<std::string> urls;
HWND parent;
@ -56,6 +58,7 @@ public:
shcount = 0;
todelete = false;
index = -1;
scrollX = scrollY = 0;
}
void setParent(HWND ahWnd) { parent = ahWnd; }
@ -77,6 +80,13 @@ public:
}
}
void saveScrollState() {
kmeleonDocInfo* di = kPlugin.kFuncs->GetDocInfo(hWnd);
if (!di) return;
scrollX = di->scrollX;
scrollY = di->scrollY;
}
bool open(bool currenttab, bool last = true) {
if (shcount<=0) return false;
@ -91,7 +101,7 @@ public:
aTitles[i] = titles[i].c_str();
}
kPlugin.kFuncs->SetMozillaSessionHistory(hWnd, aTitles, aUrls, shcount, index);
kPlugin.kFuncs->SetMozillaSessionHistory(hWnd, aTitles, aUrls, shcount, index, scrollX, scrollY);
if (last) kPlugin.kFuncs->GotoHistoryIndex(hWnd, index);
return false;
}
@ -186,6 +196,7 @@ public:
if (iter == tabsList.end()) return;
(*iter).update(aindex, acount, aurls, atitles);
(*iter).saveScrollState();
}
void setActive(bool a)
@ -263,7 +274,7 @@ public:
aTitles[i] = titles[i].c_str();
}
kPlugin.kFuncs->SetMozillaSessionHistory(hWnd, aTitles, aUrls, shcount, index);
kPlugin.kFuncs->SetMozillaSessionHistory(hWnd, aTitles, aUrls, shcount, index, 0, 0);
ShowWindow(hWnd, state);
return active;
}

@ -333,7 +333,9 @@ bool SessionStore::Read(Session& s)
if (!entries.Size()) continue;
tab.shcount = entries.Size();
tab.index = t["index"].GetInt();
tab.index = t["index"].GetInt();
tab.scrollX = t.HasMember("scrollX") ? t["scrollX"].GetInt() : 0;
tab.scrollY = t.HasMember("scrollY") ? t["scrollY"].GetInt() : 0;
for (int k=0;k<tab.shcount;k++) {
tab.urls.push_back(entries[k]["url"].GetString());
tab.titles.push_back(entries[k]["title"].GetString());
@ -423,6 +425,8 @@ void SessionStore::Write(Session& s)
Value tab;
tab.SetObject();
tab.AddMember("index", t.index, allocator);
tab.AddMember("scrollX", t.scrollX, allocator);
tab.AddMember("scrollY", t.scrollY, allocator);
Value entries;
entries.SetArray();

Loading…
Cancel
Save