Skip to content

Commit

Permalink
Add MIT license and code formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cretz committed Jul 15, 2017
1 parent 544b253 commit 45e3257
Show file tree
Hide file tree
Showing 34 changed files with 422 additions and 260 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing

Follow [Chromium Style Guide](https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md).
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Chad Retz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 7 additions & 3 deletions src/browser_stack.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "browser_stack.h"

BrowserStack::BrowserStack(Cef *cef, QWidget *parent)
namespace doogie {

BrowserStack::BrowserStack(Cef* cef, QWidget* parent)
: QStackedWidget(parent), cef_(cef) {
connect(this, &BrowserStack::currentChanged, [this](int) {
emit BrowserChanged(CurrentBrowser());
emit CurrentBrowserOrLoadingStateChanged();
});
}

QPointer<BrowserWidget> BrowserStack::NewBrowser(const QString &url) {
QPointer<BrowserWidget> BrowserStack::NewBrowser(const QString& url) {
auto widg = new BrowserWidget(cef_, url);
connect(widg, &BrowserWidget::LoadingStateChanged, [this, widg]() {
if (currentWidget() == widg) emit CurrentBrowserOrLoadingStateChanged();
Expand All @@ -18,5 +20,7 @@ QPointer<BrowserWidget> BrowserStack::NewBrowser(const QString &url) {
}

BrowserWidget* BrowserStack::CurrentBrowser() {
return (BrowserWidget*) currentWidget();
return static_cast<BrowserWidget*>(currentWidget());
}

} // namespace doogie
19 changes: 11 additions & 8 deletions src/browser_stack.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#ifndef DOOGIE_BROWSERSTACK_H_
#define DOOGIE_BROWSERSTACK_H_
#ifndef DOOGIE_BROWSER_STACK_H_
#define DOOGIE_BROWSER_STACK_H_

#include <QtWidgets>
#include "browser_widget.h"

namespace doogie {

class BrowserStack : public QStackedWidget {
Q_OBJECT
public:
explicit BrowserStack(Cef *cef, QWidget *parent = nullptr);

QPointer<BrowserWidget> NewBrowser(const QString &url);

public:
explicit BrowserStack(Cef* cef, QWidget* parent = nullptr);
QPointer<BrowserWidget> NewBrowser(const QString& url);
BrowserWidget* CurrentBrowser();

signals:
void BrowserChanged(BrowserWidget* browser);
void CurrentBrowserOrLoadingStateChanged();

private:
Cef *cef_;
Cef* cef_;
};

#endif // DOOGIE_BROWSERSTACK_H_
} // namespace doogie

#endif // DOOGIE_BROWSER_STACK_H_
32 changes: 18 additions & 14 deletions src/browser_widget.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "browser_widget.h"
#include "util.h"

BrowserWidget::BrowserWidget(Cef *cef,
const QString &url,
QWidget *parent)
namespace doogie {

BrowserWidget::BrowserWidget(Cef* cef,
const QString& url,
QWidget* parent)
: QWidget(parent), cef_(cef) {

nav_menu_ = new QMenu(this);
Expand Down Expand Up @@ -62,11 +64,11 @@ BrowserWidget::BrowserWidget(Cef *cef,
top_widg->setLayout(top_layout);

cef_widg_ = new CefWidget(cef, url, this);
connect(cef_widg_, &CefWidget::TitleChanged, [this](const QString &title) {
connect(cef_widg_, &CefWidget::TitleChanged, [this](const QString& title) {
current_title_ = title;
emit TitleChanged();
});
connect(cef_widg_, &CefWidget::FaviconChanged, [this](const QIcon &icon) {
connect(cef_widg_, &CefWidget::FaviconChanged, [this](const QIcon& icon) {
current_favicon_ = icon;
emit FaviconChanged();
});
Expand All @@ -84,9 +86,9 @@ BrowserWidget::BrowserWidget(Cef *cef,
});
connect(cef_widg_, &CefWidget::PageOpen,
[this](CefRequestHandler::WindowOpenDisposition type,
const QString &url,
const QString& url,
bool user_gesture) {
emit PageOpen((WindowOpenType) type, url, user_gesture);
emit PageOpen(static_cast<WindowOpenType>(type), url, user_gesture);
});
connect(cef_widg_, &CefWidget::DevToolsLoadComplete,
this, &BrowserWidget::DevToolsLoadComplete);
Expand All @@ -107,7 +109,7 @@ BrowserWidget::BrowserWidget(Cef *cef,
layout->addWidget(override_widg, 1, 0);
}

connect(cef_widg_, &CefWidget::UrlChanged, [this](const QString &url) {
connect(cef_widg_, &CefWidget::UrlChanged, [this](const QString& url) {
url_edit_->setText(url);
});

Expand All @@ -119,7 +121,7 @@ BrowserWidget::BrowserWidget(Cef *cef,
// TODO: handle overflow w/ ellipses
status_bar_->resize(300, status_bar_->height());
this->UpdateStatusBarLocation();
connect(cef_widg_, &CefWidget::StatusChanged, [this](const QString &status) {
connect(cef_widg_, &CefWidget::StatusChanged, [this](const QString& status) {
if (status.isEmpty()) {
status_bar_->hide();
status_bar_->clearMessage();
Expand Down Expand Up @@ -183,11 +185,11 @@ void BrowserWidget::Print() {
cef_widg_->Print();
}

void BrowserWidget::ShowDevTools(CefBaseWidget *widg) {
void BrowserWidget::ShowDevTools(CefBaseWidget* widg) {
cef_widg_->ShowDevTools(widg);
}

void BrowserWidget::ExecDevToolsJs(const QString &js) {
void BrowserWidget::ExecDevToolsJs(const QString& js) {
cef_widg_->ExecDevToolsJs(js);
}

Expand All @@ -203,11 +205,11 @@ void BrowserWidget::SetZoomLevel(double level) {
cef_widg_->SetZoomLevel(level);
}

void BrowserWidget::moveEvent(QMoveEvent *) {
void BrowserWidget::moveEvent(QMoveEvent*) {
this->UpdateStatusBarLocation();
}

void BrowserWidget::resizeEvent(QResizeEvent *) {
void BrowserWidget::resizeEvent(QResizeEvent*) {
this->UpdateStatusBarLocation();
}

Expand All @@ -228,7 +230,7 @@ void BrowserWidget::RebuildNavMenu() {
}
// Now that we have the current, we know the index to go back or forward
// We have to go backwards...
for (int i = (int)entries.size() - 1; i >= 0; i--) {
for (int i = static_cast<int>(entries.size()) - 1; i >= 0; i--) {
auto entry = entries[i];
auto action = nav_menu_->addAction(entry.title);
auto nav_index = i - current_item_index;
Expand All @@ -244,3 +246,5 @@ void BrowserWidget::RebuildNavMenu() {
}
}
}

} // namespace doogie
81 changes: 43 additions & 38 deletions src/browser_widget.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
#ifndef DOOGIE_BROWSERWIDGET_H_
#define DOOGIE_BROWSERWIDGET_H_
#ifndef DOOGIE_BROWSER_WIDGET_H_
#define DOOGIE_BROWSER_WIDGET_H_

#include <QtWidgets>
#include "cef_widget.h"

namespace doogie {

class BrowserWidget : public QWidget {
Q_OBJECT

public:
explicit BrowserWidget(Cef *cef,
const QString &url = "",
QWidget *parent = nullptr);
// Matches CEF's numbering, don't change
enum WindowOpenType {
OpenTypeUnknown,
OpenTypeCurrentTab,
OpenTypeSingletonTab,
OpenTypeNewForegroundTab,
OpenTypeNewBackgroundTab,
OpenTypeNewPopup,
OpenTypeNewWindow,
OpenTypeSaveToDisk,
OpenTypeOffTheRecord,
OpenTypeIgnoreAction
};
Q_ENUM(WindowOpenType)

explicit BrowserWidget(Cef* cef,
const QString& url = "",
QWidget* parent = nullptr);

void FocusUrlEdit();
void FocusBrowser();
Expand All @@ -26,57 +44,44 @@ class BrowserWidget : public QWidget {
void Print();

void ShowDevTools(CefBaseWidget* widg);
void ExecDevToolsJs(const QString &js);
void ExecDevToolsJs(const QString& js);
void CloseDevTools();

double GetZoomLevel();
void SetZoomLevel(double level);

// Matches CEF's numbering, don't change
enum WindowOpenType {
OpenTypeUnknown,
OpenTypeCurrentTab,
OpenTypeSingletonTab,
OpenTypeNewForegroundTab,
OpenTypeNewBackgroundTab,
OpenTypeNewPopup,
OpenTypeNewWindow,
OpenTypeSaveToDisk,
OpenTypeOffTheRecord,
OpenTypeIgnoreAction
};
Q_ENUM(WindowOpenType)
signals:
void TitleChanged();
void FaviconChanged();
void LoadingStateChanged();
void PageOpen(WindowOpenType type, const QString& url, bool user_gesture);
void DevToolsLoadComplete();
void DevToolsClosed();

protected:
void moveEvent(QMoveEvent *event);
void resizeEvent(QResizeEvent *event);
void moveEvent(QMoveEvent* event) override;
void resizeEvent(QResizeEvent* event) override;

private:
Cef *cef_;
void UpdateStatusBarLocation();
void RebuildNavMenu();

Cef* cef_;
QToolButton* back_button_;
QToolButton* forward_button_;
QMenu* nav_menu_;
QLineEdit *url_edit_;
QLineEdit* url_edit_;
QToolButton* refresh_button_;
QToolButton* stop_button_;
CefWidget *cef_widg_;
QStatusBar *status_bar_;
CefWidget* cef_widg_;
QStatusBar* status_bar_;
QIcon current_favicon_;
QString current_title_;
bool loading_ = false;
bool can_go_back_ = false;
bool can_go_forward_ = false;

void UpdateStatusBarLocation();
void RebuildNavMenu();

signals:
void TitleChanged();
void FaviconChanged();
void LoadingStateChanged();
void PageOpen(WindowOpenType type, const QString &url, bool user_gesture);
void DevToolsLoadComplete();
void DevToolsClosed();
};

#endif // DOOGIE_BROWSERWIDGET_H_
} // namespace doogie

#endif // DOOGIE_BROWSER_WIDGET_H_
10 changes: 7 additions & 3 deletions src/cef.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include "cef.h"

Cef::Cef(int argc, char *argv[]) {
namespace doogie {

Cef::Cef(int argc, char* argv[]) {
CefEnableHighDPISupport();

CefMainArgs main_args(this->MainArgs(argc, argv));

early_exit_code_ = CefExecuteProcess(main_args, NULL, NULL);
early_exit_code_ = CefExecuteProcess(main_args, nullptr, nullptr);
if (early_exit_code_ < 0) {
// Means it is not a child process, so do other init
CefSettings settings;
settings.no_sandbox = true;
if (!CefInitialize(main_args, settings, NULL, NULL)) {
if (!CefInitialize(main_args, settings, nullptr, nullptr)) {
throw std::runtime_error("Unable to initialize CEF");
}
}
Expand All @@ -27,3 +29,5 @@ int Cef::EarlyExitCode() {
void Cef::Tick() {
CefDoMessageLoopWork();
}

} // namespace doogie
12 changes: 8 additions & 4 deletions src/cef.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
# pragma warning(pop)
#endif

namespace doogie {

class Cef {
public:
Cef(int argc, char *argv[]);
Cef(int argc, char* argv[]);
~Cef();
// If >= 0, this is a child and not the UI window
int EarlyExitCode();
void Tick();

private:
int early_exit_code_;
cef_main_args_t MainArgs(int argc, char* argv[]);

cef_main_args_t MainArgs(int argc, char *argv[]);
int early_exit_code_;
};

#endif // DOOGIE_CEF_H_
} // namespace doogie

#endif // DOOGIE_CEF_H_
10 changes: 7 additions & 3 deletions src/cef_base_widget.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "cef_base_widget.h"

CefBaseWidget::CefBaseWidget(Cef *cef, QWidget *parent)
namespace doogie {

CefBaseWidget::CefBaseWidget(Cef* cef, QWidget* parent)
: QWidget(parent), cef_(cef) {
InitWindowInfo();
}
Expand All @@ -13,10 +15,12 @@ const CefWindowInfo& CefBaseWidget::WindowInfo() {
return window_info_;
}

void CefBaseWidget::moveEvent(QMoveEvent *) {
void CefBaseWidget::moveEvent(QMoveEvent*) {
this->UpdateSize();
}

void CefBaseWidget::resizeEvent(QResizeEvent *) {
void CefBaseWidget::resizeEvent(QResizeEvent*) {
this->UpdateSize();
}

} // namespace doogie
Loading

0 comments on commit 45e3257

Please sign in to comment.