Update source files for bracket style

This commit is contained in:
Marshall Greenblatt
2023-01-02 17:59:03 -05:00
parent d84b07a5cb
commit 3af3eab3e4
366 changed files with 7275 additions and 3834 deletions

View File

@@ -31,8 +31,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
CefRefPtr<Callback> callback) override {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (!test_runner::IsTestURL(url, kTestUrlPath))
if (!test_runner::IsTestURL(url, kTestUrlPath)) {
return false;
}
const std::string& message_name = request;
if (message_name.find(kTestMessageName) == 0) {

View File

@@ -35,20 +35,27 @@ std::vector<BrowserWindowOsrGtk*> g_browser_windows;
int GetCefStateModifiers(guint state) {
int modifiers = 0;
if (state & GDK_SHIFT_MASK)
if (state & GDK_SHIFT_MASK) {
modifiers |= EVENTFLAG_SHIFT_DOWN;
if (state & GDK_LOCK_MASK)
}
if (state & GDK_LOCK_MASK) {
modifiers |= EVENTFLAG_CAPS_LOCK_ON;
if (state & GDK_CONTROL_MASK)
}
if (state & GDK_CONTROL_MASK) {
modifiers |= EVENTFLAG_CONTROL_DOWN;
if (state & GDK_MOD1_MASK)
}
if (state & GDK_MOD1_MASK) {
modifiers |= EVENTFLAG_ALT_DOWN;
if (state & GDK_BUTTON1_MASK)
}
if (state & GDK_BUTTON1_MASK) {
modifiers |= EVENTFLAG_LEFT_MOUSE_BUTTON;
if (state & GDK_BUTTON2_MASK)
}
if (state & GDK_BUTTON2_MASK) {
modifiers |= EVENTFLAG_MIDDLE_MOUSE_BUTTON;
if (state & GDK_BUTTON3_MASK)
}
if (state & GDK_BUTTON3_MASK) {
modifiers |= EVENTFLAG_RIGHT_MOUSE_BUTTON;
}
return modifiers;
}
@@ -787,13 +794,15 @@ KeyboardCode GdkEventToWindowsKeyCode(const GdkEventKey* event) {
// key and a caps-lock key, GTK doesn't swap their
// |event->hardware_keycode| values but swap their |event->keyval| values.
KeyboardCode windows_key_code = KeyboardCodeFromXKeysym(event->keyval);
if (windows_key_code)
if (windows_key_code) {
return windows_key_code;
}
if (event->hardware_keycode < std::size(kHardwareCodeToGDKKeyval)) {
int keyval = kHardwareCodeToGDKKeyval[event->hardware_keycode];
if (keyval)
if (keyval) {
return KeyboardCodeFromXKeysym(keyval);
}
}
// This key is one that keyboard-layout drivers cannot change.
@@ -868,14 +877,18 @@ CefBrowserHost::DragOperationsMask GetDragOperationsMask(
GdkDragContext* drag_context) {
int allowed_ops = DRAG_OPERATION_NONE;
GdkDragAction drag_action = gdk_drag_context_get_actions(drag_context);
if (drag_action & GDK_ACTION_COPY)
if (drag_action & GDK_ACTION_COPY) {
allowed_ops |= DRAG_OPERATION_COPY;
if (drag_action & GDK_ACTION_MOVE)
}
if (drag_action & GDK_ACTION_MOVE) {
allowed_ops |= DRAG_OPERATION_MOVE;
if (drag_action & GDK_ACTION_LINK)
}
if (drag_action & GDK_ACTION_LINK) {
allowed_ops |= DRAG_OPERATION_LINK;
if (drag_action & GDK_ACTION_PRIVATE)
}
if (drag_action & GDK_ACTION_PRIVATE) {
allowed_ops |= DRAG_OPERATION_PRIVATE;
}
return static_cast<CefBrowserHost::DragOperationsMask>(allowed_ops);
}
@@ -892,8 +905,9 @@ class ScopedGLContext {
}
virtual ~ScopedGLContext() {
if (swap_buffers_ && is_valid_)
if (swap_buffers_ && is_valid_) {
glFlush();
}
}
bool IsValid() const { return is_valid_; }
@@ -1023,8 +1037,9 @@ void BrowserWindowOsrGtk::Show() {
void BrowserWindowOsrGtk::Hide() {
REQUIRE_MAIN_THREAD();
if (!browser_)
if (!browser_) {
return;
}
// Remove focus from the browser.
browser_->GetHost()->SetFocus(false);
@@ -1052,12 +1067,14 @@ void BrowserWindowOsrGtk::SetDeviceScaleFactor(float device_scale_factor) {
REQUIRE_MAIN_THREAD();
{
base::AutoLock lock_scope(lock_);
if (device_scale_factor == device_scale_factor_)
if (device_scale_factor == device_scale_factor_) {
return;
}
// Apply some sanity checks.
if (device_scale_factor < 1.0f || device_scale_factor > 4.0f)
if (device_scale_factor < 1.0f || device_scale_factor > 4.0f) {
return;
}
device_scale_factor_ = device_scale_factor;
}
@@ -1129,11 +1146,13 @@ void BrowserWindowOsrGtk::GetViewRect(CefRefPtr<CefBrowser> browser,
GtkAllocation allocation;
gtk_widget_get_allocation(glarea_, &allocation);
rect.width = DeviceToLogical(allocation.width, device_scale_factor);
if (rect.width == 0)
if (rect.width == 0) {
rect.width = 1;
}
rect.height = DeviceToLogical(allocation.height, device_scale_factor);
if (rect.height == 0)
if (rect.height == 0) {
rect.height = 1;
}
}
bool BrowserWindowOsrGtk::GetScreenPoint(CefRefPtr<CefBrowser> browser,
@@ -1223,12 +1242,14 @@ void BrowserWindowOsrGtk::OnPaint(CefRefPtr<CefBrowser> browser,
return;
}
if (!gl_enabled_)
if (!gl_enabled_) {
EnableGL();
}
ScopedGLContext scoped_gl_context(glarea_, true);
if (!scoped_gl_context.IsValid())
if (!scoped_gl_context.IsValid()) {
return;
}
renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height);
if (type == PET_VIEW && !renderer_.popup_rect().IsEmpty()) {
@@ -1397,8 +1418,9 @@ gint BrowserWindowOsrGtk::ClickEvent(GtkWidget* widget,
BrowserWindowOsrGtk* self) {
REQUIRE_MAIN_THREAD();
if (!self->browser_.get())
if (!self->browser_.get()) {
return TRUE;
}
CefRefPtr<CefBrowserHost> host = self->browser_->GetHost();
@@ -1467,8 +1489,9 @@ gint BrowserWindowOsrGtk::KeyEvent(GtkWidget* widget,
BrowserWindowOsrGtk* self) {
REQUIRE_MAIN_THREAD();
if (!self->browser_.get())
if (!self->browser_.get()) {
return TRUE;
}
CefRefPtr<CefBrowserHost> host = self->browser_->GetHost();
@@ -1481,10 +1504,12 @@ gint BrowserWindowOsrGtk::KeyEvent(GtkWidget* widget,
key_event.native_key_code = event->hardware_keycode;
key_event.modifiers = GetCefStateModifiers(event->state);
if (event->keyval >= GDK_KP_Space && event->keyval <= GDK_KP_9)
if (event->keyval >= GDK_KP_Space && event->keyval <= GDK_KP_9) {
key_event.modifiers |= EVENTFLAG_IS_KEY_PAD;
if (key_event.modifiers & EVENTFLAG_ALT_DOWN)
}
if (key_event.modifiers & EVENTFLAG_ALT_DOWN) {
key_event.is_system_key = true;
}
if (windows_key_code == VKEY_RETURN) {
// We need to treat the enter key as a key press of character \r. This
@@ -1521,8 +1546,9 @@ gint BrowserWindowOsrGtk::KeyEvent(GtkWidget* widget,
gint BrowserWindowOsrGtk::MoveEvent(GtkWidget* widget,
GdkEventMotion* event,
BrowserWindowOsrGtk* self) {
if (!self->browser_.get())
if (!self->browser_.get()) {
return TRUE;
}
CefRefPtr<CefBrowserHost> host = self->browser_->GetHost();
@@ -1578,8 +1604,9 @@ gint BrowserWindowOsrGtk::ScrollEvent(GtkWidget* widget,
BrowserWindowOsrGtk* self) {
REQUIRE_MAIN_THREAD();
if (!self->browser_.get())
if (!self->browser_.get()) {
return TRUE;
}
CefRefPtr<CefBrowserHost> host = self->browser_->GetHost();
@@ -1626,8 +1653,9 @@ gint BrowserWindowOsrGtk::FocusEvent(GtkWidget* widget,
GdkEventFocus* event,
BrowserWindowOsrGtk* self) {
// May be called on the main thread and the UI thread.
if (self->browser_.get())
if (self->browser_.get()) {
self->browser_->GetHost()->SetFocus(event->in == TRUE);
}
return TRUE;
}
@@ -1637,8 +1665,9 @@ gboolean BrowserWindowOsrGtk::TouchEvent(GtkWidget* widget,
BrowserWindowOsrGtk* self) {
REQUIRE_MAIN_THREAD();
if (!self->browser_.get())
if (!self->browser_.get()) {
return TRUE;
}
CefRefPtr<CefBrowserHost> host = self->browser_->GetHost();
@@ -1701,12 +1730,14 @@ void BrowserWindowOsrGtk::ApplyPopupOffset(int& x, int& y) const {
void BrowserWindowOsrGtk::EnableGL() {
CEF_REQUIRE_UI_THREAD();
if (gl_enabled_)
if (gl_enabled_) {
return;
}
ScopedGLContext scoped_gl_context(glarea_, false);
if (!scoped_gl_context.IsValid())
if (!scoped_gl_context.IsValid()) {
return;
}
renderer_.Initialize();
@@ -1716,12 +1747,14 @@ void BrowserWindowOsrGtk::EnableGL() {
void BrowserWindowOsrGtk::DisableGL() {
CEF_REQUIRE_UI_THREAD();
if (!gl_enabled_)
if (!gl_enabled_) {
return;
}
ScopedGLContext scoped_gl_context(glarea_, false);
if (!scoped_gl_context.IsValid())
if (!scoped_gl_context.IsValid()) {
return;
}
renderer_.Cleanup();

View File

@@ -69,8 +69,9 @@ class ScopedGLContext {
}
~ScopedGLContext() {
[NSOpenGLContext clearCurrentContext];
if (swap_buffers_)
if (swap_buffers_) {
[context_ flushBuffer];
}
}
private:
@@ -144,20 +145,23 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)detach {
renderer_ = nullptr;
browser_window_ = nullptr;
if (text_input_client_)
if (text_input_client_) {
[text_input_client_ detach];
}
}
- (CefRefPtr<CefBrowser>)getBrowser {
if (browser_window_)
if (browser_window_) {
return browser_window_->GetBrowser();
}
return nullptr;
}
- (void)setFrame:(NSRect)frameRect {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return;
}
[super setFrame:frameRect];
browser->GetHost()->WasResized();
@@ -167,8 +171,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
button:(CefBrowserHost::MouseButtonType)type
isUp:(bool)isUp {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return;
}
CefMouseEvent mouseEvent;
[self getMouseEvent:mouseEvent forEvent:event];
@@ -232,8 +237,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)mouseMoved:(NSEvent*)event {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return;
}
if (rotating_) {
// Apply rotation effect.
@@ -270,8 +276,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)mouseExited:(NSEvent*)event {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return;
}
CefMouseEvent mouseEvent;
[self getMouseEvent:mouseEvent forEvent:event];
@@ -281,8 +288,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)keyDown:(NSEvent*)event {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get() || !text_input_context_osr_mac_)
if (!browser.get() || !text_input_context_osr_mac_) {
return;
}
if ([event type] != NSEventTypeFlagsChanged) {
if (text_input_client_) {
@@ -300,8 +308,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
}
// Check for Caps lock and Toggle Touch Emulation
if (client::MainContext::Get()->TouchEventsEnabled())
if (client::MainContext::Get()->TouchEventsEnabled()) {
[self toggleTouchEmulation:event];
}
}
// OSX does not have touch screens, so we emulate it by mapping multitouch
@@ -312,10 +321,11 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
if ([event type] == NSEventTypeFlagsChanged && [event keyCode] == 0x39) {
NSUInteger flags = [event modifierFlags];
BOOL touch_enabled = flags & NSEventModifierFlagCapsLock ? YES : NO;
if (touch_enabled)
if (touch_enabled) {
self.allowedTouchTypes |= NSTouchTypeMaskDirect;
else
} else {
self.allowedTouchTypes &= ~NSTouchTypeMaskDirect;
}
}
}
@@ -409,8 +419,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)keyUp:(NSEvent*)event {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return;
}
CefKeyEvent keyEvent;
[self getKeyEvent:keyEvent forEvent:event];
@@ -420,16 +431,18 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
}
- (void)flagsChanged:(NSEvent*)event {
if ([self isKeyUpEvent:event])
if ([self isKeyUpEvent:event]) {
[self keyUp:event];
else
} else {
[self keyDown:event];
}
}
- (void)shortCircuitScrollWheelEvent:(NSEvent*)event {
if ([event phase] != NSEventPhaseEnded &&
[event phase] != NSEventPhaseCancelled)
[event phase] != NSEventPhaseCancelled) {
return;
}
[self sendScrollWheelEvet:event];
@@ -459,8 +472,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)sendScrollWheelEvet:(NSEvent*)event {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return;
}
CGEventRef cgEvent = [event CGEvent];
DCHECK(cgEvent);
@@ -508,44 +522,51 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)undo:(id)sender {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
if (browser.get()) {
browser->GetFocusedFrame()->Undo();
}
}
- (void)redo:(id)sender {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
if (browser.get()) {
browser->GetFocusedFrame()->Redo();
}
}
- (void)cut:(id)sender {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
if (browser.get()) {
browser->GetFocusedFrame()->Cut();
}
}
- (void)copy:(id)sender {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
if (browser.get()) {
browser->GetFocusedFrame()->Copy();
}
}
- (void)paste:(id)sender {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
if (browser.get()) {
browser->GetFocusedFrame()->Paste();
}
}
- (void)delete:(id)sender {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
if (browser.get()) {
browser->GetFocusedFrame()->Delete();
}
}
- (void)selectAll:(id)sender {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
if (browser.get()) {
browser->GetFocusedFrame()->SelectAll();
}
}
- (NSPoint)getClickPointForEvent:(NSEvent*)event {
@@ -561,12 +582,14 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)getKeyEvent:(CefKeyEvent&)keyEvent forEvent:(NSEvent*)event {
if ([event type] == NSEventTypeKeyDown || [event type] == NSEventTypeKeyUp) {
NSString* s = [event characters];
if ([s length] > 0)
if ([s length] > 0) {
keyEvent.character = [s characterAtIndex:0];
}
s = [event charactersIgnoringModifiers];
if ([s length] > 0)
if ([s length] > 0) {
keyEvent.unmodified_character = [s characterAtIndex:0];
}
}
if ([event type] == NSEventTypeFlagsChanged) {
@@ -605,8 +628,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
int device_x = point.x;
int device_y = point.y;
if ([self isOverPopupWidgetX:device_x andY:device_y])
if ([self isOverPopupWidgetX:device_x andY:device_y]) {
[self applyPopupOffsetToX:device_x andY:device_y];
}
// Convert to browser view coordinates.
mouseEvent.x = client::DeviceToLogical(device_x, device_scale_factor);
@@ -636,22 +660,28 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (int)getModifiersForEvent:(NSEvent*)event {
int modifiers = 0;
if ([event modifierFlags] & NSEventModifierFlagControl)
if ([event modifierFlags] & NSEventModifierFlagControl) {
modifiers |= EVENTFLAG_CONTROL_DOWN;
if ([event modifierFlags] & NSEventModifierFlagShift)
}
if ([event modifierFlags] & NSEventModifierFlagShift) {
modifiers |= EVENTFLAG_SHIFT_DOWN;
if ([event modifierFlags] & NSEventModifierFlagOption)
}
if ([event modifierFlags] & NSEventModifierFlagOption) {
modifiers |= EVENTFLAG_ALT_DOWN;
if ([event modifierFlags] & NSEventModifierFlagCommand)
}
if ([event modifierFlags] & NSEventModifierFlagCommand) {
modifiers |= EVENTFLAG_COMMAND_DOWN;
if ([event modifierFlags] & NSEventModifierFlagCapsLock)
}
if ([event modifierFlags] & NSEventModifierFlagCapsLock) {
modifiers |= EVENTFLAG_CAPS_LOCK_ON;
}
if ([event type] == NSEventTypeKeyUp || [event type] == NSEventTypeKeyDown ||
[event type] == NSEventTypeFlagsChanged) {
// Only perform this check for key events
if ([self isKeyPadEvent:event])
if ([self isKeyPadEvent:event]) {
modifiers |= EVENTFLAG_IS_KEY_PAD;
}
}
// OS X does not have a modifier for NumLock, so I'm not entirely sure how to
@@ -684,8 +714,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
}
- (BOOL)isKeyUpEvent:(NSEvent*)event {
if ([event type] != NSEventTypeFlagsChanged)
if ([event type] != NSEventTypeFlagsChanged) {
return [event type] == NSEventTypeKeyUp;
}
// FIXME: This logic fails if the user presses both Shift keys at once, for
// example: we treat releasing one of them as keyDown.
@@ -716,8 +747,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
}
- (BOOL)isKeyPadEvent:(NSEvent*)event {
if ([event modifierFlags] & NSEventModifierFlagNumericPad)
if ([event modifierFlags] & NSEventModifierFlagNumericPad) {
return true;
}
switch ([event keyCode]) {
case 71: // Clear
@@ -766,8 +798,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
}
// The Invalidate below fixes flicker when resizing.
if ([self inLiveResize] && browser.get())
if ([self inLiveResize] && browser.get()) {
browser->GetHost()->Invalidate(PET_VIEW);
}
}
// Drag and drop
@@ -833,26 +866,31 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
}
- (NSArray*)namesOfPromisedFilesDroppedAtDestination:(NSURL*)dropDest {
if (![dropDest isFileURL])
if (![dropDest isFileURL]) {
return nil;
}
if (!current_drag_data_)
if (!current_drag_data_) {
return nil;
}
size_t expected_size = current_drag_data_->GetFileContents(nullptr);
if (expected_size == 0)
if (expected_size == 0) {
return nil;
}
std::string path = [[dropDest path] UTF8String];
path.append("/");
path.append(current_drag_data_->GetFileName().ToString());
CefRefPtr<CefStreamWriter> writer = CefStreamWriter::CreateForFile(path);
if (!writer)
if (!writer) {
return nil;
}
if (current_drag_data_->GetFileContents(writer) != expected_size)
if (current_drag_data_->GetFileContents(writer) != expected_size) {
return nil;
}
return @[ [NSString stringWithUTF8String:path.c_str()] ];
}
@@ -861,11 +899,13 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
endedAt:(NSPoint)screenPoint
operation:(NSDragOperation)operation {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return;
}
if (operation == (NSDragOperationMove | NSDragOperationCopy))
if (operation == (NSDragOperationMove | NSDragOperationCopy)) {
operation &= ~NSDragOperationMove;
}
NSPoint windowPoint = [[self window] convertScreenToBase:screenPoint];
NSPoint pt = [self flipWindowPointToView:windowPoint];
@@ -880,8 +920,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return NSDragOperationNone;
}
CefRefPtr<CefDragData> drag_data;
if (!current_drag_data_) {
@@ -908,8 +949,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)draggingExited:(id<NSDraggingInfo>)sender {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
if (browser.get()) {
browser->GetHost()->DragTargetDragLeave();
}
}
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)info {
@@ -918,8 +960,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (BOOL)performDragOperation:(id<NSDraggingInfo>)info {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return NO;
}
CefMouseEvent mouseEvent;
[self getMouseEvent:mouseEvent forDragInfo:info];
@@ -931,8 +974,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser.get())
if (!browser.get()) {
return NSDragOperationNone;
}
CefMouseEvent mouseEvent;
[self getMouseEvent:mouseEvent forDragInfo:info];
@@ -1001,15 +1045,17 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
// NSAccessibility Protocol implementation.
- (BOOL)accessibilityIsIgnored {
if (!accessibility_helper_)
if (!accessibility_helper_) {
return YES;
else
} else {
return NO;
}
}
- (id)accessibilityAttributeValue:(NSString*)attribute {
if (!accessibility_helper_)
if (!accessibility_helper_) {
return [super accessibilityAttributeValue:attribute];
}
if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
return NSAccessibilityGroupRole;
} else if ([attribute isEqualToString:NSAccessibilityDescriptionAttribute]) {
@@ -1156,18 +1202,21 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)resetDeviceScaleFactor {
float device_scale_factor = 1.0f;
NSWindow* window = [self window];
if (window)
if (window) {
device_scale_factor = [window backingScaleFactor];
}
[self setDeviceScaleFactor:device_scale_factor];
}
- (void)setDeviceScaleFactor:(float)device_scale_factor {
if (device_scale_factor == device_scale_factor_)
if (device_scale_factor == device_scale_factor_) {
return;
}
// Apply some sanity checks.
if (device_scale_factor < 1.0f || device_scale_factor > 4.0f)
if (device_scale_factor < 1.0f || device_scale_factor > 4.0f) {
return;
}
device_scale_factor_ = device_scale_factor;
@@ -1185,8 +1234,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)viewDidChangeBackingProperties {
const CGFloat device_scale_factor = [self getDeviceScaleFactor];
if (device_scale_factor == device_scale_factor_)
if (device_scale_factor == device_scale_factor_) {
return;
}
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser) {
@@ -1239,8 +1289,9 @@ NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point) {
- (void)ChangeCompositionRange:(CefRange)range
character_bounds:(const CefRenderHandler::RectList&)bounds {
if (text_input_client_)
if (text_input_client_) {
[text_input_client_ ChangeCompositionRange:range character_bounds:bounds];
}
}
- (void)UpdateAccessibilityTree:(CefRefPtr<CefValue>)value {
@@ -1439,8 +1490,9 @@ void BrowserWindowOsrMacImpl::Show() {
void BrowserWindowOsrMacImpl::Hide() {
REQUIRE_MAIN_THREAD();
if (!browser_window_.browser_.get())
if (!browser_window_.browser_.get()) {
return;
}
// Remove focus from the browser.
browser_window_.browser_->GetHost()->SetFocus(false);
@@ -1462,20 +1514,23 @@ void BrowserWindowOsrMacImpl::SetBounds(int x,
void BrowserWindowOsrMacImpl::SetFocus(bool focus) {
REQUIRE_MAIN_THREAD();
if (native_browser_view_)
if (native_browser_view_) {
[native_browser_view_.window makeFirstResponder:native_browser_view_];
}
}
void BrowserWindowOsrMacImpl::SetDeviceScaleFactor(float device_scale_factor) {
REQUIRE_MAIN_THREAD();
if (native_browser_view_)
if (native_browser_view_) {
[native_browser_view_ setDeviceScaleFactor:device_scale_factor];
}
}
float BrowserWindowOsrMacImpl::GetDeviceScaleFactor() const {
REQUIRE_MAIN_THREAD();
if (native_browser_view_)
if (native_browser_view_) {
return [native_browser_view_ getDeviceScaleFactor];
}
return 1.0f;
}
@@ -1526,11 +1581,13 @@ void BrowserWindowOsrMacImpl::GetViewRect(CefRefPtr<CefBrowser> browser,
// Convert to browser view coordinates.
rect.width = DeviceToLogical(bounds.size.width, device_scale_factor);
if (rect.width == 0)
if (rect.width == 0) {
rect.width = 1;
}
rect.height = DeviceToLogical(bounds.size.height, device_scale_factor);
if (rect.height == 0)
if (rect.height == 0) {
rect.height = 1;
}
}
bool BrowserWindowOsrMacImpl::GetScreenPoint(CefRefPtr<CefBrowser> browser,
@@ -1541,8 +1598,9 @@ bool BrowserWindowOsrMacImpl::GetScreenPoint(CefRefPtr<CefBrowser> browser,
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
if (!native_browser_view_)
if (!native_browser_view_) {
return false;
}
const float device_scale_factor = [native_browser_view_ getDeviceScaleFactor];
@@ -1573,8 +1631,9 @@ bool BrowserWindowOsrMacImpl::GetScreenInfo(CefRefPtr<CefBrowser> browser,
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
if (!native_browser_view_)
if (!native_browser_view_) {
return false;
}
CefRect view_rect;
GetViewRect(browser, view_rect);
@@ -1594,8 +1653,9 @@ void BrowserWindowOsrMacImpl::OnPopupShow(CefRefPtr<CefBrowser> browser,
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
if (!native_browser_view_)
if (!native_browser_view_) {
return;
}
if (!show) {
renderer_.ClearPopupRects();
@@ -1609,8 +1669,9 @@ void BrowserWindowOsrMacImpl::OnPopupSize(CefRefPtr<CefBrowser> browser,
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
if (!native_browser_view_)
if (!native_browser_view_) {
return;
}
const float device_scale_factor = [native_browser_view_ getDeviceScaleFactor];
@@ -1630,8 +1691,9 @@ void BrowserWindowOsrMacImpl::OnPaint(
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
if (!native_browser_view_)
if (!native_browser_view_) {
return;
}
if (width <= 2 && height <= 2) {
// Ignore really small buffer sizes while the widget is starting up.
@@ -1674,8 +1736,9 @@ bool BrowserWindowOsrMacImpl::StartDragging(
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
if (!native_browser_view_)
if (!native_browser_view_) {
return false;
}
static float device_scale_factor =
[native_browser_view_ getDeviceScaleFactor];
@@ -1702,8 +1765,9 @@ void BrowserWindowOsrMacImpl::UpdateDragCursor(
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
if (native_browser_view_)
if (native_browser_view_) {
[native_browser_view_ setCurrentDragOp:operation];
}
}
void BrowserWindowOsrMacImpl::OnImeCompositionRangeChanged(

View File

@@ -57,46 +57,54 @@ void BrowserWindowOsrWin::ShowPopup(ClientWindowHandle parent_handle,
size_t width,
size_t height) {
REQUIRE_MAIN_THREAD();
if (osr_window_)
if (osr_window_) {
osr_window_->ShowPopup(parent_handle, x, y, width, height);
}
}
void BrowserWindowOsrWin::Show() {
REQUIRE_MAIN_THREAD();
if (osr_window_)
if (osr_window_) {
osr_window_->Show();
}
}
void BrowserWindowOsrWin::Hide() {
REQUIRE_MAIN_THREAD();
if (osr_window_)
if (osr_window_) {
osr_window_->Hide();
}
}
void BrowserWindowOsrWin::SetBounds(int x, int y, size_t width, size_t height) {
REQUIRE_MAIN_THREAD();
if (osr_window_)
if (osr_window_) {
osr_window_->SetBounds(x, y, width, height);
}
}
void BrowserWindowOsrWin::SetFocus(bool focus) {
REQUIRE_MAIN_THREAD();
if (osr_window_ && focus)
if (osr_window_ && focus) {
osr_window_->SetFocus();
}
}
void BrowserWindowOsrWin::SetDeviceScaleFactor(float device_scale_factor) {
REQUIRE_MAIN_THREAD();
if (device_scale_factor == device_scale_factor_)
if (device_scale_factor == device_scale_factor_) {
return;
}
// Apply some sanity checks.
if (device_scale_factor < 1.0f || device_scale_factor > 4.0f)
if (device_scale_factor < 1.0f || device_scale_factor > 4.0f) {
return;
}
device_scale_factor_ = device_scale_factor;
if (osr_window_)
if (osr_window_) {
osr_window_->SetDeviceScaleFactor(device_scale_factor);
}
}
float BrowserWindowOsrWin::GetDeviceScaleFactor() const {

View File

@@ -38,8 +38,9 @@ void SetXWindowVisible(XDisplay* xdisplay, ::Window xwindow, bool visible) {
Atom atoms[3];
int result =
XInternAtoms(xdisplay, const_cast<char**>(kAtoms), 3, false, atoms);
if (!result)
if (!result) {
NOTREACHED();
}
if (!visible) {
// Set the hidden property state value.
@@ -174,8 +175,9 @@ void BrowserWindowStdGtk::SetBounds(int x, int y, size_t width, size_t height) {
void BrowserWindowStdGtk::SetFocus(bool focus) {
REQUIRE_MAIN_THREAD();
if (browser_)
if (browser_) {
browser_->GetHost()->SetFocus(focus);
}
}
ClientWindowHandle BrowserWindowStdGtk::GetWindowHandle() const {

View File

@@ -86,8 +86,9 @@ void BrowserWindowStdMac::SetFocus(bool focus) {
ClientWindowHandle BrowserWindowStdMac::GetWindowHandle() const {
REQUIRE_MAIN_THREAD();
if (browser_)
if (browser_) {
return browser_->GetHost()->GetWindowHandle();
}
return nullptr;
}

View File

@@ -75,8 +75,9 @@ void BrowserWindowStdWin::Show() {
REQUIRE_MAIN_THREAD();
HWND hwnd = GetWindowHandle();
if (hwnd && !::IsWindowVisible(hwnd))
if (hwnd && !::IsWindowVisible(hwnd)) {
ShowWindow(hwnd, SW_SHOW);
}
}
void BrowserWindowStdWin::Hide() {
@@ -105,15 +106,17 @@ void BrowserWindowStdWin::SetBounds(int x, int y, size_t width, size_t height) {
void BrowserWindowStdWin::SetFocus(bool focus) {
REQUIRE_MAIN_THREAD();
if (browser_)
if (browser_) {
browser_->GetHost()->SetFocus(focus);
}
}
ClientWindowHandle BrowserWindowStdWin::GetWindowHandle() const {
REQUIRE_MAIN_THREAD();
if (browser_)
if (browser_) {
return browser_->GetHost()->GetWindowHandle();
}
return nullptr;
}

View File

@@ -19,8 +19,9 @@ BytesWriteHandler::BytesWriteHandler(size_t grow)
}
BytesWriteHandler::~BytesWriteHandler() {
if (data_)
if (data_) {
free(data_);
}
}
size_t BytesWriteHandler::Write(const void* ptr, size_t size, size_t n) {
@@ -43,22 +44,25 @@ int BytesWriteHandler::Seek(int64 offset, int whence) {
base::AutoLock lock_scope(lock_);
switch (whence) {
case SEEK_CUR:
if (offset_ + offset > datasize_ || offset_ + offset < 0)
if (offset_ + offset > datasize_ || offset_ + offset < 0) {
break;
}
offset_ += offset;
rv = 0;
break;
case SEEK_END: {
int64 offset_abs = std::abs(offset);
if (offset_abs > datasize_)
if (offset_abs > datasize_) {
break;
}
offset_ = datasize_ - offset_abs;
rv = 0;
break;
}
case SEEK_SET:
if (offset > datasize_ || offset < 0)
if (offset > datasize_ || offset < 0) {
break;
}
offset_ = offset;
rv = 0;
break;

View File

@@ -55,8 +55,9 @@ class ClientBrowserDelegate : public ClientAppBrowser::Delegate {
CefRefPtr<ClientAppBrowser> app,
CefRefPtr<CefCommandLine> command_line) override {
// Append Chromium command line parameters if touch events are enabled
if (client::MainContext::Get()->TouchEventsEnabled())
if (client::MainContext::Get()->TouchEventsEnabled()) {
command_line->AppendSwitchWithValue("touch-events", "enabled");
}
}
private:

View File

@@ -58,17 +58,19 @@ enum client_menu_ids {
const char kFocusedNodeChangedMessage[] = "ClientRenderer.FocusedNodeChanged";
std::string GetTimeString(const CefTime& value) {
if (value.GetTimeT() == 0)
if (value.GetTimeT() == 0) {
return "Unspecified";
}
static const char* kMonths[] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
std::string month;
if (value.month >= 1 && value.month <= 12)
if (value.month >= 1 && value.month <= 12) {
month = kMonths[value.month - 1];
else
} else {
month = "Invalid";
}
std::stringstream ss;
ss << month << " " << value.day_of_month << ", " << value.year << " "
@@ -88,8 +90,9 @@ std::string GetTimeString(const CefBaseTime& value) {
}
std::string GetBinaryString(CefRefPtr<CefBinaryValue> value) {
if (!value.get())
if (!value.get()) {
return "&nbsp;";
}
// Retrieve the value.
const size_t size = value->GetSize();
@@ -132,8 +135,9 @@ std::string GetCertStatusString(cef_cert_status_t status) {
FLAG(CERT_STATUS_SHA1_SIGNATURE_PRESENT);
FLAG(CERT_STATUS_CT_COMPLIANCE_FAILED);
if (result.empty())
if (result.empty()) {
return "&nbsp;";
}
return result;
}
@@ -156,8 +160,9 @@ std::string GetContentStatusString(cef_ssl_content_status_t status) {
FLAG(SSL_CONTENT_DISPLAYED_INSECURE_CONTENT);
FLAG(SSL_CONTENT_RAN_INSECURE_CONTENT);
if (result.empty())
if (result.empty()) {
return "&nbsp;";
}
return result;
}
@@ -175,8 +180,9 @@ void LoadErrorPage(CefRefPtr<CefFrame> frame,
<< "</a><br/>Error: " << test_runner::GetErrorString(error_code) << " ("
<< error_code << ")";
if (!other_info.empty())
if (!other_info.empty()) {
ss << "<br/>" << other_info;
}
ss << "</body></html>";
frame->LoadURL(test_runner::GetDataURI(ss.str(), "text/html"));
@@ -305,8 +311,9 @@ class ClientDownloadImageCallback : public CefDownloadImageCallback {
void OnDownloadImageFinished(const CefString& image_url,
int http_status_code,
CefRefPtr<CefImage> image) override {
if (image)
if (image) {
client_handler_->NotifyFavicon(image);
}
}
private:
@@ -467,8 +474,9 @@ void ClientHandler::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
if ((params->GetTypeFlags() & (CM_TYPEFLAG_PAGE | CM_TYPEFLAG_FRAME)) != 0) {
// Add a separator if the menu already has items.
if (model->GetCount() > 0)
if (model->GetCount() > 0) {
model->AddSeparator();
}
if (!use_chrome_runtime) {
// TODO(chrome-runtime): Add support for this.
@@ -489,27 +497,31 @@ void ClientHandler::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
model->AddSeparator();
model->AddCheckItem(CLIENT_ID_CURSOR_CHANGE_DISABLED,
"Cursor change disabled");
if (mouse_cursor_change_disabled_)
if (mouse_cursor_change_disabled_) {
model->SetChecked(CLIENT_ID_CURSOR_CHANGE_DISABLED, true);
}
model->AddSeparator();
model->AddCheckItem(CLIENT_ID_MEDIA_HANDLING_DISABLED,
"Media handling disabled");
if (media_handling_disabled_)
if (media_handling_disabled_) {
model->SetChecked(CLIENT_ID_MEDIA_HANDLING_DISABLED, true);
}
}
model->AddSeparator();
model->AddCheckItem(CLIENT_ID_OFFLINE, "Offline mode");
if (offline_)
if (offline_) {
model->SetChecked(CLIENT_ID_OFFLINE, true);
}
// Test context menu features.
BuildTestMenu(model);
}
if (delegate_)
if (delegate_) {
delegate_->OnBeforeContextMenu(model);
}
}
bool ClientHandler::OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
@@ -553,8 +565,9 @@ void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CEF_REQUIRE_UI_THREAD();
// Only update the address for the main (top-level) frame.
if (frame->IsMain())
if (frame->IsMain()) {
NotifyAddress(url);
}
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
@@ -783,13 +796,15 @@ void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
// Register handlers with the router.
test_runner::CreateMessageHandlers(message_handler_set_);
MessageHandlerSet::const_iterator it = message_handler_set_.begin();
for (; it != message_handler_set_.end(); ++it)
for (; it != message_handler_set_.end(); ++it) {
message_router_->AddHandler(*(it), false);
}
}
// Set offline mode if requested via the command-line flag.
if (offline_)
if (offline_) {
SetOfflineState(browser, true);
}
if (browser->GetHost()->GetExtension()) {
// Browsers hosting extension apps should auto-resize.
@@ -855,15 +870,17 @@ void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
CEF_REQUIRE_UI_THREAD();
// Don't display an error for downloaded files.
if (errorCode == ERR_ABORTED)
if (errorCode == ERR_ABORTED) {
return;
}
// Don't display an error for external protocols that we allow the OS to
// handle. See OnProtocolExecution().
if (errorCode == ERR_UNKNOWN_URL_SCHEME) {
std::string urlStr = frame->GetURL();
if (urlStr.find("spotify:") == 0)
if (urlStr.find("spotify:") == 0) {
return;
}
}
// Load the error page.
@@ -1021,24 +1038,27 @@ void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
message_router_->OnRenderProcessTerminated(browser);
// Don't reload if there's no start URL, or if the crash URL was specified.
if (startup_url_.empty() || startup_url_ == "chrome://crash")
if (startup_url_.empty() || startup_url_ == "chrome://crash") {
return;
}
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
std::string url = frame->GetURL();
// Don't reload if the termination occurred before any URL had successfully
// loaded.
if (url.empty())
if (url.empty()) {
return;
}
// Convert URLs to lowercase for easier comparison.
url = AsciiStrToLower(url);
const std::string& start_url = AsciiStrToLower(startup_url_);
// Don't reload the URL that just resulted in termination.
if (url.find(start_url) == 0)
if (url.find(start_url) == 0) {
return;
}
frame->LoadURL(startup_url_);
}
@@ -1049,8 +1069,9 @@ void ClientHandler::OnDocumentAvailableInMainFrame(
// Restore offline mode after main frame navigation. Otherwise, offline state
// (e.g. `navigator.onLine`) might be wrong in the renderer process.
if (offline_)
if (offline_) {
SetOfflineState(browser, true);
}
}
cef_return_value_t ClientHandler::OnBeforeResourceLoad(
@@ -1093,8 +1114,9 @@ void ClientHandler::OnProtocolExecution(CefRefPtr<CefBrowser> browser,
std::string urlStr = request->GetURL();
// Allow OS execution of Spotify URIs.
if (urlStr.find("spotify:") == 0)
if (urlStr.find("spotify:") == 0) {
allow_os_execution = true;
}
}
int ClientHandler::GetBrowserCount() const {
@@ -1152,12 +1174,14 @@ void ClientHandler::ShowSSLInformation(CefRefPtr<CefBrowser> browser) {
std::stringstream ss;
CefRefPtr<CefNavigationEntry> nav =
browser->GetHost()->GetVisibleNavigationEntry();
if (!nav)
if (!nav) {
return;
}
CefRefPtr<CefSSLStatus> ssl = nav->GetSSLStatus();
if (!ssl)
if (!ssl) {
return;
}
ss << "<html><head><title>SSL Information</title></head>"
"<body bgcolor=\"white\">"
@@ -1168,8 +1192,9 @@ void ClientHandler::ShowSSLInformation(CefRefPtr<CefBrowser> browser) {
if (CefParseURL(nav->GetURL(), urlparts)) {
CefString port(&urlparts.port);
ss << "<tr><td>Server</td><td>" << CefString(&urlparts.host).ToString();
if (!port.empty())
if (!port.empty()) {
ss << ":" << port.ToString();
}
ss << "</td></tr>";
}
@@ -1181,8 +1206,9 @@ void ClientHandler::ShowSSLInformation(CefRefPtr<CefBrowser> browser) {
ss << "</table>";
CefRefPtr<CefX509Certificate> cert = ssl->GetX509Certificate();
if (cert.get())
if (cert.get()) {
ss << GetCertificateInformation(cert, ssl->GetCertStatus());
}
ss << "</body></html>";
@@ -1230,8 +1256,9 @@ void ClientHandler::NotifyBrowserCreated(CefRefPtr<CefBrowser> browser) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnBrowserCreated(browser);
}
}
void ClientHandler::NotifyBrowserClosing(CefRefPtr<CefBrowser> browser) {
@@ -1242,8 +1269,9 @@ void ClientHandler::NotifyBrowserClosing(CefRefPtr<CefBrowser> browser) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnBrowserClosing(browser);
}
}
void ClientHandler::NotifyBrowserClosed(CefRefPtr<CefBrowser> browser) {
@@ -1254,8 +1282,9 @@ void ClientHandler::NotifyBrowserClosed(CefRefPtr<CefBrowser> browser) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnBrowserClosed(browser);
}
}
void ClientHandler::NotifyAddress(const CefString& url) {
@@ -1265,8 +1294,9 @@ void ClientHandler::NotifyAddress(const CefString& url) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnSetAddress(url);
}
}
void ClientHandler::NotifyTitle(const CefString& title) {
@@ -1276,8 +1306,9 @@ void ClientHandler::NotifyTitle(const CefString& title) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnSetTitle(title);
}
}
void ClientHandler::NotifyFavicon(CefRefPtr<CefImage> image) {
@@ -1288,8 +1319,9 @@ void ClientHandler::NotifyFavicon(CefRefPtr<CefImage> image) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnSetFavicon(image);
}
}
void ClientHandler::NotifyFullscreen(bool fullscreen) {
@@ -1300,8 +1332,9 @@ void ClientHandler::NotifyFullscreen(bool fullscreen) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnSetFullscreen(fullscreen);
}
}
void ClientHandler::NotifyAutoResize(const CefSize& new_size) {
@@ -1312,8 +1345,9 @@ void ClientHandler::NotifyAutoResize(const CefSize& new_size) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnAutoResize(new_size);
}
}
void ClientHandler::NotifyLoadingState(bool isLoading,
@@ -1326,8 +1360,9 @@ void ClientHandler::NotifyLoadingState(bool isLoading,
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnSetLoadingState(isLoading, canGoBack, canGoForward);
}
}
void ClientHandler::NotifyDraggableRegions(
@@ -1339,8 +1374,9 @@ void ClientHandler::NotifyDraggableRegions(
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnSetDraggableRegions(regions);
}
}
void ClientHandler::NotifyTakeFocus(bool next) {
@@ -1351,13 +1387,15 @@ void ClientHandler::NotifyTakeFocus(bool next) {
return;
}
if (delegate_)
if (delegate_) {
delegate_->OnTakeFocus(next);
}
}
void ClientHandler::BuildTestMenu(CefRefPtr<CefMenuModel> model) {
if (model->GetCount() > 0)
if (model->GetCount() > 0) {
model->AddSeparator();
}
// Build the sub menu.
CefRefPtr<CefMenuModel> submenu =
@@ -1368,8 +1406,9 @@ void ClientHandler::BuildTestMenu(CefRefPtr<CefMenuModel> model) {
submenu->AddRadioItem(CLIENT_ID_TESTMENU_RADIOITEM3, "Radio Item 3", 0);
// Check the check item.
if (test_menu_state_.check_item)
if (test_menu_state_.check_item) {
submenu->SetChecked(CLIENT_ID_TESTMENU_CHECKITEM, true);
}
// Check the selected radio item.
submenu->SetChecked(
@@ -1454,8 +1493,9 @@ bool ClientHandler::IsAllowedCommandId(int command_id) {
IDC_CONTENT_CONTEXT_REDO,
};
for (size_t i = 0; i < std::size(kAllowedCommandIds); ++i) {
if (command_id == kAllowedCommandIds[i])
if (command_id == kAllowedCommandIds[i]) {
return true;
}
}
return false;
}

View File

@@ -33,23 +33,26 @@ void ClientHandlerOsr::DetachOsrDelegate() {
void ClientHandlerOsr::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
if (osr_delegate_)
if (osr_delegate_) {
osr_delegate_->OnAfterCreated(browser);
}
ClientHandler::OnAfterCreated(browser);
}
void ClientHandlerOsr::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
if (osr_delegate_)
if (osr_delegate_) {
osr_delegate_->OnBeforeClose(browser);
}
ClientHandler::OnBeforeClose(browser);
}
bool ClientHandlerOsr::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return false;
}
return osr_delegate_->GetRootScreenRect(browser, rect);
}
@@ -70,31 +73,35 @@ bool ClientHandlerOsr::GetScreenPoint(CefRefPtr<CefBrowser> browser,
int& screenX,
int& screenY) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return false;
}
return osr_delegate_->GetScreenPoint(browser, viewX, viewY, screenX, screenY);
}
bool ClientHandlerOsr::GetScreenInfo(CefRefPtr<CefBrowser> browser,
CefScreenInfo& screen_info) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return false;
}
return osr_delegate_->GetScreenInfo(browser, screen_info);
}
void ClientHandlerOsr::OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return;
}
return osr_delegate_->OnPopupShow(browser, show);
}
void ClientHandlerOsr::OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return;
}
return osr_delegate_->OnPopupSize(browser, rect);
}
@@ -105,8 +112,9 @@ void ClientHandlerOsr::OnPaint(CefRefPtr<CefBrowser> browser,
int width,
int height) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return;
}
osr_delegate_->OnPaint(browser, type, dirtyRects, buffer, width, height);
}
@@ -116,8 +124,9 @@ void ClientHandlerOsr::OnAcceleratedPaint(
const CefRenderHandler::RectList& dirtyRects,
void* share_handle) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return;
}
osr_delegate_->OnAcceleratedPaint(browser, type, dirtyRects, share_handle);
}
@@ -128,8 +137,9 @@ bool ClientHandlerOsr::StartDragging(
int x,
int y) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return false;
}
return osr_delegate_->StartDragging(browser, drag_data, allowed_ops, x, y);
}
@@ -137,8 +147,9 @@ void ClientHandlerOsr::UpdateDragCursor(
CefRefPtr<CefBrowser> browser,
CefRenderHandler::DragOperation operation) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return;
}
osr_delegate_->UpdateDragCursor(browser, operation);
}
@@ -147,16 +158,18 @@ void ClientHandlerOsr::OnImeCompositionRangeChanged(
const CefRange& selection_range,
const CefRenderHandler::RectList& character_bounds) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return;
}
osr_delegate_->OnImeCompositionRangeChanged(browser, selection_range,
character_bounds);
}
void ClientHandlerOsr::OnAccessibilityTreeChange(CefRefPtr<CefValue> value) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return;
}
osr_delegate_->UpdateAccessibilityTree(value);
}
@@ -178,8 +191,9 @@ bool ClientHandlerOsr::OnCursorChange(CefRefPtr<CefBrowser> browser,
void ClientHandlerOsr::OnAccessibilityLocationChange(
CefRefPtr<CefValue> value) {
CEF_REQUIRE_UI_THREAD();
if (!osr_delegate_)
if (!osr_delegate_) {
return;
}
osr_delegate_->UpdateAccessibilityLocation(value);
}

View File

@@ -133,20 +133,24 @@ CefRect ClampBoundsToDisplay(const CefRect& dip_bounds) {
CefRect bounds = dip_bounds;
if (bounds.width > work_area.width)
if (bounds.width > work_area.width) {
bounds.width = work_area.width;
if (bounds.height > work_area.height)
}
if (bounds.height > work_area.height) {
bounds.height = work_area.height;
}
if (bounds.x < work_area.x)
if (bounds.x < work_area.x) {
bounds.x = work_area.x;
else if (bounds.x + bounds.width >= work_area.x + work_area.width)
} else if (bounds.x + bounds.width >= work_area.x + work_area.width) {
bounds.x = work_area.x + work_area.width - bounds.width;
}
if (bounds.y < work_area.y)
if (bounds.y < work_area.y) {
bounds.y = work_area.y;
else if (bounds.y + bounds.height >= work_area.y + work_area.height)
} else if (bounds.y + bounds.height >= work_area.y + work_area.height) {
bounds.y = work_area.y + work_area.height - bounds.height;
}
return bounds;
}

View File

@@ -24,8 +24,9 @@ const char kPromptTextId[] = "cef_prompt_text";
std::string GetPromptText(GtkDialog* dialog) {
GtkWidget* widget = static_cast<GtkWidget*>(
g_object_get_data(G_OBJECT(dialog), kPromptTextId));
if (widget)
if (widget) {
return gtk_entry_get_text(GTK_ENTRY(widget));
}
return std::string();
}
@@ -43,8 +44,9 @@ std::string GetDescriptionFromMimeType(const std::string& mime_type) {
for (size_t i = 0;
i < sizeof(kWildCardMimeTypes) / sizeof(kWildCardMimeTypes[0]); ++i) {
if (mime_type == std::string(kWildCardMimeTypes[i].mime_type) + "/*")
if (mime_type == std::string(kWildCardMimeTypes[i].mime_type) + "/*") {
return std::string(kWildCardMimeTypes[i].label);
}
}
return std::string();
@@ -58,8 +60,9 @@ void AddFilters(GtkFileChooser* chooser,
for (size_t j = 0; j < accept_filters.size(); ++j) {
const std::string& filter = accept_filters[j];
if (filter.empty())
if (filter.empty()) {
continue;
}
std::vector<std::string> extensions;
std::string description;
@@ -75,8 +78,9 @@ void AddFilters(GtkFileChooser* chooser,
for (size_t i = 0; i <= size; ++i) {
if (i == size || exts[i] == ';') {
std::string ext(exts, last, i - last);
if (!ext.empty() && ext[0] == '.')
if (!ext.empty() && ext[0] == '.') {
extensions.push_back(ext);
}
last = i + 1;
}
}
@@ -89,33 +93,38 @@ void AddFilters(GtkFileChooser* chooser,
std::vector<CefString> ext;
CefGetExtensionsForMimeType(filter, ext);
for (size_t x = 0; x < ext.size(); ++x)
for (size_t x = 0; x < ext.size(); ++x) {
extensions.push_back("." + ext[x].ToString());
}
}
if (extensions.empty())
if (extensions.empty()) {
continue;
}
GtkFileFilter* gtk_filter = gtk_file_filter_new();
std::string ext_str;
for (size_t x = 0; x < extensions.size(); ++x) {
const std::string& pattern = "*" + extensions[x];
if (x != 0)
if (x != 0) {
ext_str += ";";
}
ext_str += pattern;
gtk_file_filter_add_pattern(gtk_filter, pattern.c_str());
}
if (description.empty())
if (description.empty()) {
description = ext_str;
else
} else {
description += " (" + ext_str + ")";
}
gtk_file_filter_set_name(gtk_filter, description.c_str());
gtk_file_chooser_add_filter(chooser, gtk_filter);
if (!has_filter)
if (!has_filter) {
has_filter = true;
}
filters->push_back(gtk_filter);
}
@@ -137,8 +146,9 @@ GtkWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
if (root_window) {
GtkWidget* window = root_window->GetWindowHandle();
DCHECK(window);
if (!window)
if (!window) {
LOG(ERROR) << "No GtkWindow for browser";
}
return GTK_WINDOW(window);
}
return nullptr;
@@ -212,8 +222,9 @@ bool ClientDialogHandlerGtk::OnBeforeUnloadDialog(
void ClientDialogHandlerGtk::OnResetDialogState(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
if (!gtk_dialog_)
if (!gtk_dialog_) {
return;
}
gtk_widget_destroy(gtk_dialog_);
gtk_dialog_ = nullptr;
@@ -274,8 +285,9 @@ void ClientDialogHandlerGtk::OnFileDialogContinue(
title_str.c_str(), GTK_WINDOW(window), action, "_Cancel",
GTK_RESPONSE_CANCEL, accept_button, GTK_RESPONSE_ACCEPT, nullptr);
if (params.mode == FILE_DIALOG_OPEN_MULTIPLE)
if (params.mode == FILE_DIALOG_OPEN_MULTIPLE) {
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
}
if (!params.default_file_path.empty() && params.mode == FILE_DIALOG_SAVE) {
const std::string& file_path = params.default_file_path;
@@ -326,10 +338,11 @@ void ClientDialogHandlerGtk::OnFileDialogContinue(
gtk_widget_destroy(dialog);
if (success)
if (success) {
params.callback->Continue(files);
else
} else {
params.callback->Cancel();
}
}
void ClientDialogHandlerGtk::OnJSDialogContinue(const OnJSDialogParams& params,
@@ -380,8 +393,9 @@ void ClientDialogHandlerGtk::OnJSDialogContinue(const OnJSDialogParams& params,
GtkWidget* ok_button =
gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), "_OK", GTK_RESPONSE_OK);
if (params.dialog_type != JSDIALOGTYPE_PROMPT)
if (params.dialog_type != JSDIALOGTYPE_PROMPT) {
gtk_widget_grab_focus(ok_button);
}
if (params.dialog_type == JSDIALOGTYPE_PROMPT) {
GtkWidget* content_area =

View File

@@ -64,8 +64,9 @@ class DialogCallback : public CefRunFileDialogCallback {
// Send a message back to the render process with the list of file paths.
std::string response;
for (int i = 0; i < static_cast<int>(file_paths.size()); ++i) {
if (!response.empty())
if (!response.empty()) {
response += "|"; // Use a delimiter disallowed in file paths.
}
response += file_paths[i];
}
@@ -100,11 +101,13 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (!test_runner::IsTestURL(url, kTestUrlPath))
if (!test_runner::IsTestURL(url, kTestUrlPath)) {
return false;
}
if (!dialog_state_.get())
if (!dialog_state_.get()) {
dialog_state_ = new DialogState;
}
// Make sure we're only running one dialog at a time.
DCHECK(!dialog_state_->pending_);

View File

@@ -37,8 +37,9 @@ ImageCache::ImageInfo::ImageInfo(const std::string& id,
: id_(id), reps_(reps), internal_(internal), force_reload_(force_reload) {
#ifndef NDEBUG
DCHECK(!id_.empty());
if (id_ != kEmptyId)
if (id_ != kEmptyId) {
DCHECK(!reps_.empty());
}
#endif
}
@@ -129,8 +130,9 @@ void ImageCache::LoadImages(const ImageInfoSet& image_info,
// Load the image.
images.push_back(nullptr);
if (!missing_images)
if (!missing_images) {
missing_images = true;
}
}
if (missing_images) {
@@ -147,8 +149,9 @@ CefRefPtr<CefImage> ImageCache::GetCachedImage(const std::string& image_id) {
DCHECK(!image_id.empty());
ImageMap::const_iterator it = image_map_.find(image_id);
if (it != image_map_.end())
if (it != image_map_.end()) {
return it->second;
}
return nullptr;
}
@@ -156,14 +159,17 @@ CefRefPtr<CefImage> ImageCache::GetCachedImage(const std::string& image_id) {
// static
ImageCache::ImageType ImageCache::GetImageType(const std::string& path) {
std::string ext = file_util::GetFileExtension(path);
if (ext.empty())
if (ext.empty()) {
return TYPE_NONE;
}
ext = AsciiStrToLower(ext);
if (ext == "png")
if (ext == "png") {
return TYPE_PNG;
if (ext == "jpg" || ext == "jpeg")
}
if (ext == "jpg" || ext == "jpeg") {
return TYPE_JPEG;
}
return TYPE_NONE;
}
@@ -226,12 +232,14 @@ bool ImageCache::LoadImageContents(const std::string& path,
CEF_REQUIRE_FILE_USER_BLOCKING_THREAD();
*type = GetImageType(path);
if (*type == TYPE_NONE)
if (*type == TYPE_NONE) {
return false;
}
if (internal) {
if (!LoadBinaryResource(path.c_str(), *contents))
if (!LoadBinaryResource(path.c_str(), *contents)) {
return false;
}
} else if (!file_util::ReadFileToString(path, contents)) {
return false;
}
@@ -276,8 +284,9 @@ CefRefPtr<CefImage> ImageCache::CreateImage(const std::string& image_id,
// Shouldn't be creating an image if one already exists.
DCHECK(!content.image_);
if (content.contents_.empty())
if (content.contents_.empty()) {
return nullptr;
}
CefRefPtr<CefImage> image = CefImage::CreateImage();

View File

@@ -21,16 +21,17 @@ const char kDefaultUrl[] = "http://www.google.com";
// Returns the ARGB value for |color|.
cef_color_t ParseColor(const std::string& color) {
const std::string& colorToLower = AsciiStrToLower(color);
if (colorToLower == "black")
if (colorToLower == "black") {
return CefColorSetARGB(255, 0, 0, 0);
else if (colorToLower == "blue")
} else if (colorToLower == "blue") {
return CefColorSetARGB(255, 0, 0, 255);
else if (colorToLower == "green")
} else if (colorToLower == "green") {
return CefColorSetARGB(255, 0, 255, 0);
else if (colorToLower == "red")
} else if (colorToLower == "red") {
return CefColorSetARGB(255, 255, 0, 0);
else if (colorToLower == "white")
} else if (colorToLower == "white") {
return CefColorSetARGB(255, 255, 255, 255);
}
// Use the default color.
return 0;
@@ -45,10 +46,12 @@ MainContextImpl::MainContextImpl(CefRefPtr<CefCommandLine> command_line,
DCHECK(command_line_.get());
// Set the main URL.
if (command_line_->HasSwitch(switches::kUrl))
if (command_line_->HasSwitch(switches::kUrl)) {
main_url_ = command_line_->GetSwitchValue(switches::kUrl);
if (main_url_.empty())
}
if (main_url_.empty()) {
main_url_ = kDefaultUrl;
}
// Whether windowless (off-screen) rendering will be used.
use_windowless_rendering_ =
@@ -187,17 +190,20 @@ bool MainContextImpl::UseDefaultPopup() {
void MainContextImpl::PopulateSettings(CefSettings* settings) {
client::ClientAppBrowser::PopulateSettings(command_line_, *settings);
if (use_chrome_runtime_)
if (use_chrome_runtime_) {
settings->chrome_runtime = true;
}
CefString(&settings->cache_path) =
command_line_->GetSwitchValue(switches::kCachePath);
if (use_windowless_rendering_)
if (use_windowless_rendering_) {
settings->windowless_rendering_enabled = true;
}
if (browser_background_color_ != 0)
if (browser_background_color_ != 0) {
settings->background_color = browser_background_color_;
}
if (command_line_->HasSwitch("lang")) {
// Use the same locale for the Accept-Language HTTP request header.
@@ -209,8 +215,9 @@ void MainContextImpl::PopulateSettings(CefSettings* settings) {
void MainContextImpl::PopulateBrowserSettings(CefBrowserSettings* settings) {
settings->windowless_frame_rate = windowless_frame_rate_;
if (browser_background_color_ != 0)
if (browser_background_color_ != 0) {
settings->background_color = browser_background_color_;
}
if (use_chrome_runtime_ &&
command_line_->HasSwitch(switches::kHideChromeStatusBubble)) {
@@ -228,8 +235,9 @@ void MainContextImpl::PopulateOsrSettings(OsrRendererSettings* settings) {
settings->external_begin_frame_enabled = external_begin_frame_enabled_;
settings->begin_frame_rate = windowless_frame_rate_;
if (browser_background_color_ != 0)
if (browser_background_color_ != 0) {
settings->background_color = browser_background_color_;
}
}
RootWindowManager* MainContextImpl::GetRootWindowManager() {
@@ -245,8 +253,9 @@ bool MainContextImpl::Initialize(const CefMainArgs& args,
DCHECK(!initialized_);
DCHECK(!shutdown_);
if (!CefInitialize(args, settings, application, windows_sandbox_info))
if (!CefInitialize(args, settings, application, windows_sandbox_info)) {
return false;
}
// Need to create the RootWindowManager after calling CefInitialize because
// TempWindowX11 uses cef_get_xdisplay().

View File

@@ -61,8 +61,9 @@ int MainMessageLoopMultithreadedWin::Run() {
// Run the application message loop.
while (GetMessage(&msg, nullptr, 0, 0)) {
// Allow processing of dialog messages.
if (dialog_hwnd_ && IsDialogMessage(dialog_hwnd_, &msg))
if (dialog_hwnd_ && IsDialogMessage(dialog_hwnd_, &msg)) {
continue;
}
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);

View File

@@ -254,15 +254,17 @@ class MediaObserver : public CefMediaObserver {
private:
CefRefPtr<CefMediaSource> GetSource(const std::string& source_urn) {
CefRefPtr<CefMediaSource> source = media_router_->GetSource(source_urn);
if (!source)
if (!source) {
return nullptr;
}
return source;
}
CefRefPtr<CefMediaSink> GetSink(const std::string& sink_id) {
SinkInfoMap::const_iterator it = sink_info_map_.find(sink_id);
if (it != sink_info_map_.end())
if (it != sink_info_map_.end()) {
return it->second->sink;
}
return nullptr;
}
@@ -278,8 +280,9 @@ class MediaObserver : public CefMediaObserver {
const std::string& sink_id,
const CefMediaSinkDeviceInfo& device_info) {
// Discard callbacks that arrive after a new call to OnSinks().
if (sink_query_id != pending_sink_query_id_)
if (sink_query_id != pending_sink_query_id_) {
return;
}
SinkInfoMap::const_iterator it = sink_info_map_.find(sink_id);
if (it != sink_info_map_.end()) {
@@ -295,8 +298,9 @@ class MediaObserver : public CefMediaObserver {
CefRefPtr<CefMediaRoute> GetRoute(const std::string& route_id) {
RouteMap::const_iterator it = route_map_.find(route_id);
if (it != route_map_.end())
if (it != route_map_.end()) {
return it->second;
}
return nullptr;
}
@@ -327,10 +331,9 @@ class MediaObserver : public CefMediaObserver {
sink_dict->SetInt("port", info->device_info.port);
sink_dict->SetString("model_name",
CefString(&info->device_info.model_name));
sink_dict->SetString("type",
info->sink->IsCastSink()
? "cast"
: info->sink->IsDialSink() ? "dial" : "unknown");
sink_dict->SetString("type", info->sink->IsCastSink() ? "cast"
: info->sink->IsDialSink() ? "dial"
: "unknown");
sinks_list->SetDictionary(idx, sink_dict);
}
@@ -389,8 +392,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (!test_runner::IsTestURL(url, kTestUrlPath))
if (!test_runner::IsTestURL(url, kTestUrlPath)) {
return false;
}
// Parse |request| as a JSON dictionary.
CefRefPtr<CefDictionaryValue> request_dict = ParseJSON(request);
@@ -400,8 +404,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
}
// Verify the "name" key.
if (!VerifyKey(request_dict, kNameKey, VTYPE_STRING, callback))
if (!VerifyKey(request_dict, kNameKey, VTYPE_STRING, callback)) {
return true;
}
const std::string& message_name = request_dict->GetString(kNameKey);
if (message_name == kNameValueSubscribe) {
@@ -432,11 +437,13 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Create a new route.
// Verify the "source_urn" key.
if (!VerifyKey(request_dict, kSourceKey, VTYPE_STRING, callback))
if (!VerifyKey(request_dict, kSourceKey, VTYPE_STRING, callback)) {
return true;
}
// Verify the "sink_id" key.
if (!VerifyKey(request_dict, kSinkKey, VTYPE_STRING, callback))
if (!VerifyKey(request_dict, kSinkKey, VTYPE_STRING, callback)) {
return true;
}
const std::string& source_urn = request_dict->GetString(kSourceKey);
const std::string& sink_id = request_dict->GetString(kSinkKey);
@@ -451,8 +458,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Terminate an existing route.
// Verify the "route" key.
if (!VerifyKey(request_dict, kRouteKey, VTYPE_STRING, callback))
if (!VerifyKey(request_dict, kRouteKey, VTYPE_STRING, callback)) {
return true;
}
const std::string& route_id = request_dict->GetString(kRouteKey);
std::string error;
@@ -466,11 +474,13 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Send a route message.
// Verify the "route_id" key.
if (!VerifyKey(request_dict, kRouteKey, VTYPE_STRING, callback))
if (!VerifyKey(request_dict, kRouteKey, VTYPE_STRING, callback)) {
return true;
}
// Verify the "message" key.
if (!VerifyKey(request_dict, kMessageKey, VTYPE_STRING, callback))
if (!VerifyKey(request_dict, kMessageKey, VTYPE_STRING, callback)) {
return true;
}
const std::string& route_id = request_dict->GetString(kRouteKey);
const std::string& message = request_dict->GetString(kMessageKey);
@@ -503,8 +513,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Convert a JSON string to a dictionary value.
static CefRefPtr<CefDictionaryValue> ParseJSON(const CefString& string) {
CefRefPtr<CefValue> value = CefParseJSON(string, JSON_PARSER_RFC);
if (value.get() && value->GetType() == VTYPE_DICTIONARY)
if (value.get() && value->GetType() == VTYPE_DICTIONARY) {
return value->GetDictionary();
}
return nullptr;
}

View File

@@ -38,8 +38,7 @@ void OsrAXTree::UpdateTreeData(CefRefPtr<CefDictionaryValue> value) {
OsrAccessibilityHelper::OsrAccessibilityHelper(CefRefPtr<CefValue> value,
CefRefPtr<CefBrowser> browser)
: focused_node_id_(-1),
browser_(browser) {
: focused_node_id_(-1), browser_(browser) {
UpdateAccessibilityTree(value);
}

View File

@@ -41,16 +41,18 @@ void OsrAXNode::UpdateLocation(CefRefPtr<CefDictionaryValue> value) {
}
void OsrAXNode::UpdateValue(CefRefPtr<CefDictionaryValue> value) {
if (value->HasKey("role"))
if (value->HasKey("role")) {
role_ = value->GetString("role");
}
if (value->HasKey("child_ids")) {
CefRefPtr<CefListValue> childs = value->GetList("child_ids");
// Reset child Ids
child_ids_.clear();
for (size_t idx = 0; idx < childs->GetSize(); idx++)
for (size_t idx = 0; idx < childs->GetSize(); idx++) {
child_ids_.push_back(
OsrAccessibilityHelper::CastToInt(childs->GetValue(idx)));
}
}
// Update Location
if (value->HasKey("location")) {
@@ -85,24 +87,29 @@ void OsrAXNode::UpdateValue(CefRefPtr<CefDictionaryValue> value) {
if (attributes_ && attributes_->HasKey("childTreeId")) {
child_tree_id_ = attributes_->GetString("childTreeId");
}
if (attributes_ && attributes_->HasKey("name"))
if (attributes_ && attributes_->HasKey("name")) {
name_ = attributes_->GetString("name");
if (attributes_ && attributes_->HasKey("value"))
}
if (attributes_ && attributes_->HasKey("value")) {
value_ = attributes_->GetString("value");
if (attributes_ && attributes_->HasKey("description"))
}
if (attributes_ && attributes_->HasKey("description")) {
description_ = attributes_->GetString("description");
}
}
}
CefWindowHandle OsrAXNode::GetWindowHandle() const {
if (accessibility_helper_)
if (accessibility_helper_) {
return accessibility_helper_->GetWindowHandle();
}
return nullptr;
}
CefRefPtr<CefBrowser> OsrAXNode::GetBrowser() const {
if (accessibility_helper_)
if (accessibility_helper_) {
return accessibility_helper_->GetBrowser();
}
return nullptr;
}
@@ -149,8 +156,9 @@ int OsrAXNode::GetChildCount() const {
OsrAXNode* OsrAXNode::ChildAtIndex(int index) const {
int count = static_cast<int>(child_ids_.size());
if (index < count)
if (index < count) {
return accessibility_helper_->GetNode(OsrAXTreeId(), child_ids_[index]);
}
if ((index == count) && (!child_tree_id_.empty())) {
OsrAXNode* childTreeRootNode =
accessibility_helper_->GetTreeRootNode(child_tree_id_);

View File

@@ -15,220 +15,327 @@
namespace {
NSString* AxRoleToNSAxRole(const std::string& role_string) {
if (role_string == "abbr")
if (role_string == "abbr") {
return NSAccessibilityGroupRole;
if (role_string == "alertDialog")
}
if (role_string == "alertDialog") {
return NSAccessibilityGroupRole;
if (role_string == "alert")
}
if (role_string == "alert") {
return NSAccessibilityGroupRole;
if (role_string == "annotation")
}
if (role_string == "annotation") {
return NSAccessibilityUnknownRole;
if (role_string == "application")
}
if (role_string == "application") {
return NSAccessibilityGroupRole;
if (role_string == "article")
}
if (role_string == "article") {
return NSAccessibilityGroupRole;
if (role_string == "audio")
}
if (role_string == "audio") {
return NSAccessibilityGroupRole;
if (role_string == "banner")
}
if (role_string == "banner") {
return NSAccessibilityGroupRole;
if (role_string == "blockquote")
}
if (role_string == "blockquote") {
return NSAccessibilityGroupRole;
if (role_string == "busyIndicator")
}
if (role_string == "busyIndicator") {
return NSAccessibilityBusyIndicatorRole;
if (role_string == "button")
}
if (role_string == "button") {
return NSAccessibilityButtonRole;
if (role_string == "buttonDropDown")
}
if (role_string == "buttonDropDown") {
return NSAccessibilityButtonRole;
if (role_string == "canvas")
}
if (role_string == "canvas") {
return NSAccessibilityImageRole;
if (role_string == "caption")
}
if (role_string == "caption") {
return NSAccessibilityGroupRole;
if (role_string == "checkBox")
}
if (role_string == "checkBox") {
return NSAccessibilityCheckBoxRole;
if (role_string == "colorWell")
}
if (role_string == "colorWell") {
return NSAccessibilityColorWellRole;
if (role_string == "column")
}
if (role_string == "column") {
return NSAccessibilityColumnRole;
if (role_string == "comboBox")
}
if (role_string == "comboBox") {
return NSAccessibilityComboBoxRole;
if (role_string == "complementary")
}
if (role_string == "complementary") {
return NSAccessibilityGroupRole;
if (role_string == "contentInfo")
}
if (role_string == "contentInfo") {
return NSAccessibilityGroupRole;
if (role_string == "definition")
}
if (role_string == "definition") {
return NSAccessibilityGroupRole;
if (role_string == "descriptionListDetail")
}
if (role_string == "descriptionListDetail") {
return NSAccessibilityGroupRole;
if (role_string == "descriptionList")
}
if (role_string == "descriptionList") {
return NSAccessibilityListRole;
if (role_string == "descriptionListTerm")
}
if (role_string == "descriptionListTerm") {
return NSAccessibilityGroupRole;
if (role_string == "details")
}
if (role_string == "details") {
return NSAccessibilityGroupRole;
if (role_string == "dialog")
}
if (role_string == "dialog") {
return NSAccessibilityGroupRole;
if (role_string == "directory")
}
if (role_string == "directory") {
return NSAccessibilityListRole;
if (role_string == "disclosureTriangle")
}
if (role_string == "disclosureTriangle") {
return NSAccessibilityDisclosureTriangleRole;
if (role_string == "div")
}
if (role_string == "div") {
return NSAccessibilityGroupRole;
if (role_string == "document")
}
if (role_string == "document") {
return NSAccessibilityGroupRole;
if (role_string == "embeddedObject")
}
if (role_string == "embeddedObject") {
return NSAccessibilityGroupRole;
if (role_string == "figcaption")
}
if (role_string == "figcaption") {
return NSAccessibilityGroupRole;
if (role_string == "figure")
}
if (role_string == "figure") {
return NSAccessibilityGroupRole;
if (role_string == "footer")
}
if (role_string == "footer") {
return NSAccessibilityGroupRole;
if (role_string == "form")
}
if (role_string == "form") {
return NSAccessibilityGroupRole;
if (role_string == "genericContainer")
}
if (role_string == "genericContainer") {
return NSAccessibilityGroupRole;
if (role_string == "grid")
}
if (role_string == "grid") {
return NSAccessibilityGroupRole;
if (role_string == "group")
}
if (role_string == "group") {
return NSAccessibilityGroupRole;
if (role_string == "iframe")
}
if (role_string == "iframe") {
return NSAccessibilityGroupRole;
if (role_string == "iframePresentational")
}
if (role_string == "iframePresentational") {
return NSAccessibilityGroupRole;
if (role_string == "ignored")
}
if (role_string == "ignored") {
return NSAccessibilityUnknownRole;
if (role_string == "imageMapLink")
}
if (role_string == "imageMapLink") {
return NSAccessibilityLinkRole;
if (role_string == "imageMap")
}
if (role_string == "imageMap") {
return NSAccessibilityGroupRole;
if (role_string == "image")
}
if (role_string == "image") {
return NSAccessibilityImageRole;
if (role_string == "labelText")
}
if (role_string == "labelText") {
return NSAccessibilityGroupRole;
if (role_string == "legend")
}
if (role_string == "legend") {
return NSAccessibilityGroupRole;
if (role_string == "link")
}
if (role_string == "link") {
return NSAccessibilityLinkRole;
if (role_string == "listBoxOption")
}
if (role_string == "listBoxOption") {
return NSAccessibilityStaticTextRole;
if (role_string == "listBox")
}
if (role_string == "listBox") {
return NSAccessibilityListRole;
if (role_string == "listItem")
}
if (role_string == "listItem") {
return NSAccessibilityGroupRole;
if (role_string == "list")
}
if (role_string == "list") {
return NSAccessibilityListRole;
if (role_string == "log")
}
if (role_string == "log") {
return NSAccessibilityGroupRole;
if (role_string == "main")
}
if (role_string == "main") {
return NSAccessibilityGroupRole;
if (role_string == "mark")
}
if (role_string == "mark") {
return NSAccessibilityGroupRole;
if (role_string == "marquee")
}
if (role_string == "marquee") {
return NSAccessibilityGroupRole;
if (role_string == "math")
}
if (role_string == "math") {
return NSAccessibilityGroupRole;
if (role_string == "menu")
}
if (role_string == "menu") {
return NSAccessibilityMenuRole;
if (role_string == "menuBar")
}
if (role_string == "menuBar") {
return NSAccessibilityMenuBarRole;
if (role_string == "menuButton")
}
if (role_string == "menuButton") {
return NSAccessibilityButtonRole;
if (role_string == "menuItem")
}
if (role_string == "menuItem") {
return NSAccessibilityMenuItemRole;
if (role_string == "menuItemCheckBox")
}
if (role_string == "menuItemCheckBox") {
return NSAccessibilityMenuItemRole;
if (role_string == "menuItemRadio")
}
if (role_string == "menuItemRadio") {
return NSAccessibilityMenuItemRole;
if (role_string == "menuListOption")
}
if (role_string == "menuListOption") {
return NSAccessibilityMenuItemRole;
if (role_string == "menuListPopup")
}
if (role_string == "menuListPopup") {
return NSAccessibilityUnknownRole;
if (role_string == "meter")
}
if (role_string == "meter") {
return NSAccessibilityProgressIndicatorRole;
if (role_string == "navigation")
}
if (role_string == "navigation") {
return NSAccessibilityGroupRole;
if (role_string == "note")
}
if (role_string == "note") {
return NSAccessibilityGroupRole;
if (role_string == "outline")
}
if (role_string == "outline") {
return NSAccessibilityOutlineRole;
if (role_string == "paragraph")
}
if (role_string == "paragraph") {
return NSAccessibilityGroupRole;
if (role_string == "popUpButton")
}
if (role_string == "popUpButton") {
return NSAccessibilityPopUpButtonRole;
if (role_string == "pre")
}
if (role_string == "pre") {
return NSAccessibilityGroupRole;
if (role_string == "presentational")
}
if (role_string == "presentational") {
return NSAccessibilityGroupRole;
if (role_string == "progressIndicator")
}
if (role_string == "progressIndicator") {
return NSAccessibilityProgressIndicatorRole;
if (role_string == "radioButton")
}
if (role_string == "radioButton") {
return NSAccessibilityRadioButtonRole;
if (role_string == "radioGroup")
}
if (role_string == "radioGroup") {
return NSAccessibilityRadioGroupRole;
if (role_string == "region")
}
if (role_string == "region") {
return NSAccessibilityGroupRole;
if (role_string == "row")
}
if (role_string == "row") {
return NSAccessibilityRowRole;
if (role_string == "ruler")
}
if (role_string == "ruler") {
return NSAccessibilityRulerRole;
if (role_string == "scrollBar")
}
if (role_string == "scrollBar") {
return NSAccessibilityScrollBarRole;
if (role_string == "search")
}
if (role_string == "search") {
return NSAccessibilityGroupRole;
if (role_string == "searchBox")
}
if (role_string == "searchBox") {
return NSAccessibilityTextFieldRole;
if (role_string == "slider")
}
if (role_string == "slider") {
return NSAccessibilitySliderRole;
if (role_string == "sliderThumb")
}
if (role_string == "sliderThumb") {
return NSAccessibilityValueIndicatorRole;
if (role_string == "spinButton")
}
if (role_string == "spinButton") {
return NSAccessibilityIncrementorRole;
if (role_string == "splitter")
}
if (role_string == "splitter") {
return NSAccessibilitySplitterRole;
if (role_string == "staticText")
}
if (role_string == "staticText") {
return NSAccessibilityStaticTextRole;
if (role_string == "status")
}
if (role_string == "status") {
return NSAccessibilityGroupRole;
if (role_string == "svgRoot")
}
if (role_string == "svgRoot") {
return NSAccessibilityGroupRole;
if (role_string == "switch")
}
if (role_string == "switch") {
return NSAccessibilityCheckBoxRole;
if (role_string == "tabGroup")
}
if (role_string == "tabGroup") {
return NSAccessibilityTabGroupRole;
if (role_string == "tabList")
}
if (role_string == "tabList") {
return NSAccessibilityTabGroupRole;
if (role_string == "tabPanel")
}
if (role_string == "tabPanel") {
return NSAccessibilityGroupRole;
if (role_string == "tab")
}
if (role_string == "tab") {
return NSAccessibilityRadioButtonRole;
if (role_string == "tableHeaderContainer")
}
if (role_string == "tableHeaderContainer") {
return NSAccessibilityGroupRole;
if (role_string == "table")
}
if (role_string == "table") {
return NSAccessibilityTableRole;
if (role_string == "textField")
}
if (role_string == "textField") {
return NSAccessibilityTextFieldRole;
if (role_string == "time")
}
if (role_string == "time") {
return NSAccessibilityGroupRole;
if (role_string == "timer")
}
if (role_string == "timer") {
return NSAccessibilityGroupRole;
if (role_string == "toggleButton")
}
if (role_string == "toggleButton") {
return NSAccessibilityCheckBoxRole;
if (role_string == "toolbar")
}
if (role_string == "toolbar") {
return NSAccessibilityToolbarRole;
if (role_string == "treeGrid")
}
if (role_string == "treeGrid") {
return NSAccessibilityTableRole;
if (role_string == "treeItem")
}
if (role_string == "treeItem") {
return NSAccessibilityRowRole;
if (role_string == "tree")
}
if (role_string == "tree") {
return NSAccessibilityOutlineRole;
if (role_string == "unknown")
}
if (role_string == "unknown") {
return NSAccessibilityUnknownRole;
if (role_string == "tooltip")
}
if (role_string == "tooltip") {
return NSAccessibilityGroupRole;
if (role_string == "video")
}
if (role_string == "video") {
return NSAccessibilityGroupRole;
if (role_string == "window")
}
if (role_string == "window") {
return NSAccessibilityWindowRole;
}
return [NSString stringWithUTF8String:role_string.c_str()];
}
@@ -387,8 +494,9 @@ inline int MiddleY(const CefRect& rect) {
- (id)accessibilityAttributeValue:(NSString*)attribute {
NSObject* typed_parent = CAST_CEF_NATIVE_ACCESSIBLE_TO_NSOBJECT(parent_);
if (!node_)
if (!node_) {
return nil;
}
if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
return [self axRole];
} else if ([attribute

View File

@@ -40,72 +40,105 @@ void ClientToScreen(HWND hwnd, LPRECT lpRect) {
// Helper function to convert to MSAARole
int AxRoleToMSAARole(const std::string& role_string) {
if (role_string == "alert")
if (role_string == "alert") {
return ROLE_SYSTEM_ALERT;
if (role_string == "application")
}
if (role_string == "application") {
return ROLE_SYSTEM_APPLICATION;
if (role_string == "buttonDropDown")
}
if (role_string == "buttonDropDown") {
return ROLE_SYSTEM_BUTTONDROPDOWN;
if (role_string == "popUpButton")
}
if (role_string == "popUpButton") {
return ROLE_SYSTEM_BUTTONMENU;
if (role_string == "checkBox")
}
if (role_string == "checkBox") {
return ROLE_SYSTEM_CHECKBUTTON;
if (role_string == "comboBox")
}
if (role_string == "comboBox") {
return ROLE_SYSTEM_COMBOBOX;
if (role_string == "dialog")
}
if (role_string == "dialog") {
return ROLE_SYSTEM_DIALOG;
if (role_string == "genericContainer")
}
if (role_string == "genericContainer") {
return ROLE_SYSTEM_GROUPING;
if (role_string == "group")
}
if (role_string == "group") {
return ROLE_SYSTEM_GROUPING;
if (role_string == "image")
}
if (role_string == "image") {
return ROLE_SYSTEM_GRAPHIC;
if (role_string == "link")
}
if (role_string == "link") {
return ROLE_SYSTEM_LINK;
if (role_string == "locationBar")
}
if (role_string == "locationBar") {
return ROLE_SYSTEM_GROUPING;
if (role_string == "menuBar")
}
if (role_string == "menuBar") {
return ROLE_SYSTEM_MENUBAR;
if (role_string == "menuItem")
}
if (role_string == "menuItem") {
return ROLE_SYSTEM_MENUITEM;
if (role_string == "menuListPopup")
}
if (role_string == "menuListPopup") {
return ROLE_SYSTEM_MENUPOPUP;
if (role_string == "tree")
}
if (role_string == "tree") {
return ROLE_SYSTEM_OUTLINE;
if (role_string == "treeItem")
}
if (role_string == "treeItem") {
return ROLE_SYSTEM_OUTLINEITEM;
if (role_string == "tab")
}
if (role_string == "tab") {
return ROLE_SYSTEM_PAGETAB;
if (role_string == "tabList")
}
if (role_string == "tabList") {
return ROLE_SYSTEM_PAGETABLIST;
if (role_string == "pane")
}
if (role_string == "pane") {
return ROLE_SYSTEM_PANE;
if (role_string == "progressIndicator")
}
if (role_string == "progressIndicator") {
return ROLE_SYSTEM_PROGRESSBAR;
if (role_string == "button")
}
if (role_string == "button") {
return ROLE_SYSTEM_PUSHBUTTON;
if (role_string == "radioButton")
}
if (role_string == "radioButton") {
return ROLE_SYSTEM_RADIOBUTTON;
if (role_string == "scrollBar")
}
if (role_string == "scrollBar") {
return ROLE_SYSTEM_SCROLLBAR;
if (role_string == "splitter")
}
if (role_string == "splitter") {
return ROLE_SYSTEM_SEPARATOR;
if (role_string == "slider")
}
if (role_string == "slider") {
return ROLE_SYSTEM_SLIDER;
if (role_string == "staticText")
}
if (role_string == "staticText") {
return ROLE_SYSTEM_STATICTEXT;
if (role_string == "textField")
}
if (role_string == "textField") {
return ROLE_SYSTEM_TEXT;
if (role_string == "titleBar")
}
if (role_string == "titleBar") {
return ROLE_SYSTEM_TITLEBAR;
if (role_string == "toolbar")
}
if (role_string == "toolbar") {
return ROLE_SYSTEM_TOOLBAR;
if (role_string == "webView")
}
if (role_string == "webView") {
return ROLE_SYSTEM_GROUPING;
if (role_string == "window")
}
if (role_string == "window") {
return ROLE_SYSTEM_WINDOW;
if (role_string == "client")
}
if (role_string == "client") {
return ROLE_SYSTEM_CLIENT;
}
// This is the default role for MSAA.
return ROLE_SYSTEM_CLIENT;
}
@@ -235,17 +268,19 @@ struct CefIAccessible : public IAccessible {
// Handles ref counting and querying for other supported interfaces.
// We only support, IUnknown, IDispatch and IAccessible.
STDMETHODIMP CefIAccessible::QueryInterface(REFIID riid, void** ppvObject) {
if (riid == IID_IAccessible)
if (riid == IID_IAccessible) {
*ppvObject = static_cast<IAccessible*>(this);
else if (riid == IID_IDispatch)
} else if (riid == IID_IDispatch) {
*ppvObject = static_cast<IDispatch*>(this);
else if (riid == IID_IUnknown)
} else if (riid == IID_IUnknown) {
*ppvObject = static_cast<IUnknown*>(this);
else
} else {
*ppvObject = nullptr;
}
if (*ppvObject)
if (*ppvObject) {
reinterpret_cast<IUnknown*>(*ppvObject)->AddRef();
}
return (*ppvObject) ? S_OK : E_NOINTERFACE;
}
@@ -259,8 +294,9 @@ STDMETHODIMP_(ULONG) CefIAccessible::Release() {
ULONG ulRefCnt = InterlockedDecrement((LONG volatile*)&ref_count_);
if (ulRefCnt == 0) {
// Remove reference from OsrAXNode
if (node_)
if (node_) {
node_->Destroy();
}
delete this;
}
@@ -286,8 +322,9 @@ STDMETHODIMP CefIAccessible::get_accParent(IDispatch** ppdispParent) {
}
}
if (parent)
if (parent) {
parent->AddRef();
}
*ppdispParent = parent;
retCode = (*ppdispParent) ? S_OK : S_FALSE;
}
@@ -327,15 +364,17 @@ STDMETHODIMP CefIAccessible::get_accChild(VARIANT varChild,
// Convert to 0 based index and get Child Node.
OsrAXNode* child = node_->ChildAtIndex(varChild.lVal - 1);
// Fallback to focused node
if (!child)
if (!child) {
child = node_->GetAccessibilityHelper()->GetFocusedNode();
}
*ppdispChild = child->GetNativeAccessibleObject(node_);
}
if (*ppdispChild == nullptr)
if (*ppdispChild == nullptr) {
retCode = S_FALSE;
else
} else {
(*ppdispChild)->AddRef();
}
}
}
}
@@ -436,10 +475,11 @@ STDMETHODIMP CefIAccessible::get_accKeyboardShortcut(
BSTR* pszKeyboardShortcut) {
HRESULT retCode = DATACHECK(node_);
if (SUCCEEDED(retCode)) {
if (pszKeyboardShortcut && VALID_CHILDID(varChild))
if (pszKeyboardShortcut && VALID_CHILDID(varChild)) {
*pszKeyboardShortcut = ::SysAllocString(L"None");
else
} else {
retCode = E_INVALIDARG;
}
}
return retCode;
}
@@ -450,8 +490,9 @@ STDMETHODIMP CefIAccessible::get_accFocus(VARIANT* pFocusChild) {
if (SUCCEEDED(retCode)) {
OsrAXNode* focusedNode = node_->GetAccessibilityHelper()->GetFocusedNode();
CefNativeAccessible* nativeObj = nullptr;
if (focusedNode)
if (focusedNode) {
nativeObj = focusedNode->GetNativeAccessibleObject(nullptr);
}
if (nativeObj) {
if (nativeObj == this) {
@@ -473,10 +514,11 @@ STDMETHODIMP CefIAccessible::get_accFocus(VARIANT* pFocusChild) {
STDMETHODIMP CefIAccessible::get_accSelection(VARIANT* pvarChildren) {
HRESULT retCode = DATACHECK(node_);
if (SUCCEEDED(retCode)) {
if (pvarChildren)
if (pvarChildren) {
pvarChildren->vt = VT_EMPTY;
else
} else {
retCode = E_INVALIDARG;
}
}
return retCode;
}
@@ -486,10 +528,11 @@ STDMETHODIMP CefIAccessible::get_accDefaultAction(VARIANT varChild,
BSTR* pszDefaultAction) {
HRESULT retCode = DATACHECK(node_);
if (SUCCEEDED(retCode)) {
if (pszDefaultAction && VALID_CHILDID(varChild))
if (pszDefaultAction && VALID_CHILDID(varChild)) {
*pszDefaultAction = ::SysAllocString(L"Push");
else
} else {
retCode = E_INVALIDARG;
}
}
return retCode;
}
@@ -661,8 +704,9 @@ void OsrAXNode::NotifyAccessibilityEvent(std::string event_type) const {
void OsrAXNode::Destroy() {
CefIAccessible* ptr = static_cast<CefIAccessible*>(platform_accessibility_);
if (ptr)
if (ptr) {
ptr->MarkDestroyed();
}
platform_accessibility_ = nullptr;
}

View File

@@ -37,8 +37,9 @@ namespace {
template <class T>
std::shared_ptr<T> to_com_ptr(T* obj) {
return std::shared_ptr<T>(obj, [](T* p) {
if (p)
if (p) {
p->Release();
}
});
}
@@ -695,8 +696,9 @@ std::shared_ptr<ID3DBlob> Device::compile_shader(const std::string& source_code,
}
return std::shared_ptr<ID3DBlob>(blob, [](ID3DBlob* p) {
if (p)
if (p) {
p->Release();
}
});
}

View File

@@ -24,23 +24,29 @@ namespace {
DWORD DragOperationToDropEffect(CefRenderHandler::DragOperation allowed_ops) {
DWORD effect = DROPEFFECT_NONE;
if (allowed_ops & DRAG_OPERATION_COPY)
if (allowed_ops & DRAG_OPERATION_COPY) {
effect |= DROPEFFECT_COPY;
if (allowed_ops & DRAG_OPERATION_LINK)
}
if (allowed_ops & DRAG_OPERATION_LINK) {
effect |= DROPEFFECT_LINK;
if (allowed_ops & DRAG_OPERATION_MOVE)
}
if (allowed_ops & DRAG_OPERATION_MOVE) {
effect |= DROPEFFECT_MOVE;
}
return effect;
}
CefRenderHandler::DragOperationsMask DropEffectToDragOperation(DWORD effect) {
DWORD operation = DRAG_OPERATION_NONE;
if (effect & DROPEFFECT_COPY)
if (effect & DROPEFFECT_COPY) {
operation |= DRAG_OPERATION_COPY;
if (effect & DROPEFFECT_LINK)
}
if (effect & DROPEFFECT_LINK) {
operation |= DRAG_OPERATION_LINK;
if (effect & DROPEFFECT_MOVE)
}
if (effect & DROPEFFECT_MOVE) {
operation |= DRAG_OPERATION_MOVE;
}
return static_cast<CefRenderHandler::DragOperationsMask>(operation);
}
@@ -93,8 +99,9 @@ void GetStorageForFileDescriptor(STGMEDIUM* storage,
// Documentation for the CF_HTML format is available at
// http://msdn.microsoft.com/en-us/library/aa767917(VS.85).aspx
std::string HtmlToCFHtml(const std::string& html, const std::string& base_url) {
if (html.empty())
if (html.empty()) {
return std::string();
}
#define MAX_DIGITS 10
#define MAKE_NUMBER_FORMAT_1(digits) MAKE_NUMBER_FORMAT_2(digits)
@@ -279,8 +286,9 @@ CefRefPtr<CefDragData> DataObjectToDragData(IDataObject* data_object) {
CefRefPtr<CefDragData> drag_data = CefDragData::Create();
IEnumFORMATETC* enumFormats = nullptr;
HRESULT res = data_object->EnumFormatEtc(DATADIR_GET, &enumFormats);
if (res != S_OK)
if (res != S_OK) {
return drag_data;
}
enumFormats->Reset();
const int kCelt = 10;
@@ -294,8 +302,9 @@ CefRefPtr<CefDragData> DataObjectToDragData(IDataObject* data_object) {
if (!(format == CF_UNICODETEXT || format == CF_TEXT ||
format == moz_url_format || format == html_format ||
format == CF_HDROP) ||
rgelt[i].tymed != TYMED_HGLOBAL)
rgelt[i].tymed != TYMED_HGLOBAL) {
continue;
}
STGMEDIUM medium;
if (data_object->GetData(&rgelt[i], &medium) == S_OK) {
if (!medium.hGlobal) {
@@ -336,18 +345,21 @@ CefRefPtr<CefDragData> DataObjectToDragData(IDataObject* data_object) {
const unsigned num_files = DragQueryFileW(hdrop, 0xffffffff, 0, 0);
for (unsigned int x = 0; x < num_files; ++x) {
wchar_t filename[kMaxFilenameLen];
if (!DragQueryFileW(hdrop, x, filename, kMaxFilenameLen))
if (!DragQueryFileW(hdrop, x, filename, kMaxFilenameLen)) {
continue;
}
WCHAR* name = wcsrchr(filename, '\\');
drag_data->AddFile(filename, (name ? name + 1 : filename));
}
}
if (medium.hGlobal)
if (medium.hGlobal) {
GlobalUnlock(medium.hGlobal);
if (format == CF_HDROP)
}
if (format == CF_HDROP) {
DragFinish((HDROP)hGlobal);
else
} else {
ReleaseStgMedium(&medium);
}
}
}
} while (res == S_OK);
@@ -366,8 +378,9 @@ HRESULT DropTargetWin::DragEnter(IDataObject* data_object,
DWORD key_state,
POINTL cursor_position,
DWORD* effect) {
if (!callback_)
if (!callback_) {
return E_UNEXPECTED;
}
CefRefPtr<CefDragData> drag_data = current_drag_data_;
if (!drag_data) {
@@ -394,8 +407,9 @@ CefBrowserHost::DragOperationsMask DropTargetWin::StartDragging(
current_drag_data_ = drag_data->Clone();
current_drag_data_->ResetFileContents();
HRESULT res = DoDragDrop(dataObject, dropSource, effect, &resEffect);
if (res != DRAGDROP_S_DROP)
if (res != DRAGDROP_S_DROP) {
resEffect = DROPEFFECT_NONE;
}
current_drag_data_ = nullptr;
}
return DropEffectToDragOperation(resEffect);
@@ -404,8 +418,9 @@ CefBrowserHost::DragOperationsMask DropTargetWin::StartDragging(
HRESULT DropTargetWin::DragOver(DWORD key_state,
POINTL cursor_position,
DWORD* effect) {
if (!callback_)
if (!callback_) {
return E_UNEXPECTED;
}
CefMouseEvent ev = ToMouseEvent(cursor_position, key_state, hWnd_);
CefBrowserHost::DragOperationsMask mask = DropEffectToDragOperation(*effect);
mask = callback_->OnDragOver(ev, mask);
@@ -414,8 +429,9 @@ HRESULT DropTargetWin::DragOver(DWORD key_state,
}
HRESULT DropTargetWin::DragLeave() {
if (!callback_)
if (!callback_) {
return E_UNEXPECTED;
}
callback_->OnDragLeave();
return S_OK;
}
@@ -424,8 +440,9 @@ HRESULT DropTargetWin::Drop(IDataObject* data_object,
DWORD key_state,
POINTL cursor_position,
DWORD* effect) {
if (!callback_)
if (!callback_) {
return E_UNEXPECTED;
}
CefMouseEvent ev = ToMouseEvent(cursor_position, key_state, hWnd_);
CefBrowserHost::DragOperationsMask mask = DropEffectToDragOperation(*effect);
mask = callback_->OnDrop(ev, mask);
@@ -458,8 +475,9 @@ HRESULT DragEnumFormatEtc::CreateEnumFormatEtc(
UINT cfmt,
FORMATETC* afmt,
IEnumFORMATETC** ppEnumFormatEtc) {
if (cfmt == 0 || afmt == 0 || ppEnumFormatEtc == 0)
if (cfmt == 0 || afmt == 0 || ppEnumFormatEtc == 0) {
return E_INVALIDARG;
}
*ppEnumFormatEtc = new DragEnumFormatEtc(afmt, cfmt);
@@ -479,8 +497,9 @@ HRESULT DragEnumFormatEtc::Next(ULONG celt,
}
// store result
if (pceltFetched != 0)
if (pceltFetched != 0) {
*pceltFetched = copied;
}
// did we copy all that was requested?
return (copied == celt) ? S_OK : S_FALSE;
@@ -522,8 +541,9 @@ DragEnumFormatEtc::DragEnumFormatEtc(FORMATETC* pFormatEtc, int nNumFormats) {
DragEnumFormatEtc::~DragEnumFormatEtc() {
// first free any DVTARGETDEVICE structures
for (ULONG i = 0; i < m_nNumFormats; i++) {
if (m_pFormatEtc[i].ptd)
if (m_pFormatEtc[i].ptd) {
CoTaskMemFree(m_pFormatEtc[i].ptd);
}
}
// now free the main array
@@ -594,8 +614,9 @@ HRESULT DataObjectWin::GetData(FORMATETC* pFormatEtc, STGMEDIUM* pMedium) {
int idx;
// try to match the specified FORMATETC with one of our supported formats
if ((idx = LookupFormatEtc(pFormatEtc)) == -1)
if ((idx = LookupFormatEtc(pFormatEtc)) == -1) {
return DV_E_FORMATETC;
}
// found a match - transfer data into supplied storage medium
pMedium->tymed = m_pFormatEtc[idx].tymed;

View File

@@ -37,17 +37,19 @@ namespace client {
AddRef(); \
return S_OK; \
}
#define IUNKNOWN_IMPLEMENTATION \
ULONG __stdcall AddRef() { return ++ref_count_; } \
ULONG __stdcall Release() { \
if (--ref_count_ == 0) { \
delete this; \
return 0U; \
} \
return ref_count_; \
} \
\
protected: \
#define IUNKNOWN_IMPLEMENTATION \
ULONG __stdcall AddRef() { \
return ++ref_count_; \
} \
ULONG __stdcall Release() { \
if (--ref_count_ == 0) { \
delete this; \
return 0U; \
} \
return ref_count_; \
} \
\
protected: \
ULONG ref_count_;
class DropTargetWin : public IDropTarget {

View File

@@ -46,12 +46,14 @@ void GetCompositionSelectionRange(HIMC imc,
::ImmGetCompositionString(imc, GCS_COMPATTR, &attribute_data[0],
attribute_size);
for (start = 0; start < attribute_size; ++start) {
if (IsSelectionAttribute(attribute_data[start]))
if (IsSelectionAttribute(attribute_data[start])) {
break;
}
}
for (end = start; end < attribute_size; ++end) {
if (!IsSelectionAttribute(attribute_data[end]))
if (!IsSelectionAttribute(attribute_data[end])) {
break;
}
}
*target_start = start;
@@ -133,8 +135,9 @@ void OsrImeHandlerWin::CreateImeWindow() {
if (PRIMARYLANGID(input_language_id_) == LANG_CHINESE ||
PRIMARYLANGID(input_language_id_) == LANG_JAPANESE) {
if (!system_caret_) {
if (::CreateCaret(hwnd_, nullptr, 1, 1))
if (::CreateCaret(hwnd_, nullptr, 1, 1)) {
system_caret_ = true;
}
}
}
}
@@ -149,24 +152,28 @@ void OsrImeHandlerWin::DestroyImeWindow() {
void OsrImeHandlerWin::MoveImeWindow() {
// Does nothing when the target window has no input focus.
if (GetFocus() != hwnd_)
if (GetFocus() != hwnd_) {
return;
}
CefRect rc = ime_rect_;
int location = cursor_index_;
// If location is not specified fall back to the composition range start.
if (location == -1)
if (location == -1) {
location = composition_range_.from;
}
// Offset location by the composition range start if required.
if (location >= composition_range_.from)
if (location >= composition_range_.from) {
location -= composition_range_.from;
}
if (location < static_cast<int>(composition_bounds_.size()))
if (location < static_cast<int>(composition_bounds_.size())) {
rc = composition_bounds_[location];
else
} else {
return;
}
HIMC imc = ::ImmGetContext(hwnd_);
if (imc) {
@@ -251,8 +258,9 @@ void OsrImeHandlerWin::GetCompositionInfo(
// Find out the range selected by the user.
int target_start = length;
int target_end = length;
if (lparam & GCS_COMPATTR)
if (lparam & GCS_COMPATTR) {
GetCompositionSelectionRange(imc, &target_start, &target_end);
}
// Retrieve the selection range information. If CS_NOMOVECARET is specified
// it means the cursor should not be moved and we therefore place the caret at
@@ -271,8 +279,9 @@ void OsrImeHandlerWin::GetCompositionInfo(
}
// Retrieve the clause segmentations and convert them to underlines.
if (lparam & GCS_COMPCLAUSE)
if (lparam & GCS_COMPCLAUSE) {
GetCompositionUnderlines(imc, target_start, target_end, underlines);
}
// Set default underlines in case there is no clause information.
if (!underlines.size()) {
@@ -304,11 +313,13 @@ bool OsrImeHandlerWin::GetString(HIMC imc,
WPARAM lparam,
int type,
CefString& result) {
if (!(lparam & type))
if (!(lparam & type)) {
return false;
}
LONG string_size = ::ImmGetCompositionString(imc, type, nullptr, 0);
if (string_size <= 0)
if (string_size <= 0) {
return false;
}
// For trailing nullptr - ImmGetCompositionString excludes that.
string_size += sizeof(WCHAR);

View File

@@ -35,32 +35,40 @@ PopupLayer::PopupLayer(const std::shared_ptr<d3d11::Device>& device)
void PopupLayer::set_bounds(const CefRect& bounds) {
const auto comp = composition();
if (!comp)
if (!comp) {
return;
}
const auto outer_width = comp->width();
const auto outer_height = comp->height();
if (outer_width == 0 || outer_height == 0)
if (outer_width == 0 || outer_height == 0) {
return;
}
original_bounds_ = bounds;
bounds_ = bounds;
// If x or y are negative, move them to 0.
if (bounds_.x < 0)
if (bounds_.x < 0) {
bounds_.x = 0;
if (bounds_.y < 0)
}
if (bounds_.y < 0) {
bounds_.y = 0;
}
// If popup goes outside the view, try to reposition origin
if (bounds_.x + bounds_.width > outer_width)
if (bounds_.x + bounds_.width > outer_width) {
bounds_.x = outer_width - bounds_.width;
if (bounds_.y + bounds_.height > outer_height)
}
if (bounds_.y + bounds_.height > outer_height) {
bounds_.y = outer_height - bounds_.height;
}
// If x or y became negative, move them to 0 again.
if (bounds_.x < 0)
if (bounds_.x < 0) {
bounds_.x = 0;
if (bounds_.y < 0)
}
if (bounds_.y < 0) {
bounds_.y = 0;
}
const auto x = bounds_.x / float(outer_width);
const auto y = bounds_.y / float(outer_height);
@@ -82,14 +90,16 @@ bool OsrRenderHandlerWinD3D11::Initialize(CefRefPtr<CefBrowser> browser,
// Create a D3D11 device instance.
device_ = d3d11::Device::create();
DCHECK(device_);
if (!device_)
if (!device_) {
return false;
}
// Create a D3D11 swapchain for the window.
swap_chain_ = device_->create_swapchain(hwnd());
DCHECK(swap_chain_);
if (!swap_chain_)
if (!swap_chain_) {
return false;
}
// Create the browser layer.
browser_layer_ = std::make_shared<BrowserLayer>(device_);
@@ -124,15 +134,17 @@ bool OsrRenderHandlerWinD3D11::IsOverPopupWidget(int x, int y) const {
int OsrRenderHandlerWinD3D11::GetPopupXOffset() const {
CEF_REQUIRE_UI_THREAD();
if (popup_layer_)
if (popup_layer_) {
return popup_layer_->xoffset();
}
return 0;
}
int OsrRenderHandlerWinD3D11::GetPopupYOffset() const {
CEF_REQUIRE_UI_THREAD();
if (popup_layer_)
if (popup_layer_) {
return popup_layer_->yoffset();
}
return 0;
}

View File

@@ -54,8 +54,9 @@ OsrRenderer::~OsrRenderer() {
}
void OsrRenderer::Initialize() {
if (initialized_)
if (initialized_) {
return;
}
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
VERIFY_NO_ERROR;
@@ -94,13 +95,15 @@ void OsrRenderer::Initialize() {
}
void OsrRenderer::Cleanup() {
if (texture_id_ != 0)
if (texture_id_ != 0) {
glDeleteTextures(1, &texture_id_);
}
}
void OsrRenderer::Render() {
if (view_width_ == 0 || view_height_ == 0)
if (view_width_ == 0 || view_height_ == 0) {
return;
}
DCHECK(initialized_);
@@ -246,8 +249,9 @@ void OsrRenderer::OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) {
void OsrRenderer::OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) {
if (rect.width <= 0 || rect.height <= 0)
if (rect.width <= 0 || rect.height <= 0) {
return;
}
original_popup_rect_ = rect;
popup_rect_ = GetPopupRectInWebView(original_popup_rect_);
}
@@ -255,20 +259,26 @@ void OsrRenderer::OnPopupSize(CefRefPtr<CefBrowser> browser,
CefRect OsrRenderer::GetPopupRectInWebView(const CefRect& original_rect) {
CefRect rc(original_rect);
// if x or y are negative, move them to 0.
if (rc.x < 0)
if (rc.x < 0) {
rc.x = 0;
if (rc.y < 0)
}
if (rc.y < 0) {
rc.y = 0;
}
// if popup goes outside the view, try to reposition origin
if (rc.x + rc.width > view_width_)
if (rc.x + rc.width > view_width_) {
rc.x = view_width_ - rc.width;
if (rc.y + rc.height > view_height_)
}
if (rc.y + rc.height > view_height_) {
rc.y = view_height_ - rc.height;
}
// if x or y became negative, move them to 0 again.
if (rc.x < 0)
if (rc.x < 0) {
rc.x = 0;
if (rc.y < 0)
}
if (rc.y < 0) {
rc.y = 0;
}
return rc;
}
@@ -283,8 +293,9 @@ void OsrRenderer::OnPaint(CefRefPtr<CefBrowser> browser,
const void* buffer,
int width,
int height) {
if (!initialized_)
if (!initialized_) {
Initialize();
}
if (IsTransparent()) {
// Enable alpha blending.
@@ -307,8 +318,9 @@ void OsrRenderer::OnPaint(CefRefPtr<CefBrowser> browser,
view_width_ = width;
view_height_ = height;
if (settings_.show_update_rect)
if (settings_.show_update_rect) {
update_rect_ = dirtyRects[0];
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, view_width_);
VERIFY_NO_ERROR;
@@ -357,10 +369,12 @@ void OsrRenderer::OnPaint(CefRefPtr<CefBrowser> browser,
skip_rows = -y;
y = 0;
}
if (x + w > view_width_)
if (x + w > view_width_) {
w -= x + w - view_width_;
if (y + h > view_height_)
}
if (y + h > view_height_) {
h -= y + h - view_height_;
}
// Update the popup rectangle.
glPixelStorei(GL_UNPACK_ROW_LENGTH, width);

View File

@@ -188,12 +188,14 @@ void OsrWindowWin::Show() {
return;
}
if (!browser_)
if (!browser_) {
return;
}
// Show the native window if not currently visible.
if (hwnd_ && !::IsWindowVisible(hwnd_))
if (hwnd_ && !::IsWindowVisible(hwnd_)) {
ShowWindow(hwnd_, SW_SHOW);
}
if (hidden_) {
// Set the browser as visible.
@@ -212,8 +214,9 @@ void OsrWindowWin::Hide() {
return;
}
if (!browser_)
if (!browser_) {
return;
}
// Remove focus from the browser.
browser_->GetHost()->SetFocus(false);
@@ -261,8 +264,9 @@ void OsrWindowWin::SetDeviceScaleFactor(float device_scale_factor) {
return;
}
if (device_scale_factor == device_scale_factor_)
if (device_scale_factor == device_scale_factor_) {
return;
}
device_scale_factor_ = device_scale_factor;
if (browser_) {
@@ -318,8 +322,9 @@ void OsrWindowWin::Create(HWND parent_hwnd, const RECT& rect) {
ime_handler_.reset(new OsrImeHandlerWin(hwnd_));
// Enable Touch Events if requested
if (client::MainContext::Get()->TouchEventsEnabled())
if (client::MainContext::Get()->TouchEventsEnabled()) {
RegisterTouchWindow(hwnd_, 0);
}
// Notify the window owner.
NotifyNativeWindowCreated(hwnd_);
@@ -359,8 +364,9 @@ void OsrWindowWin::RegisterOsrClass(HINSTANCE hInstance,
HBRUSH background_brush) {
// Only register the class one time.
static bool class_registered = false;
if (class_registered)
if (class_registered) {
return;
}
class_registered = true;
WNDCLASSEX wcex;
@@ -458,8 +464,9 @@ LRESULT CALLBACK OsrWindowWin::OsrWndProc(HWND hWnd,
CEF_REQUIRE_UI_THREAD();
OsrWindowWin* self = GetUserDataPtr<OsrWindowWin*>(hWnd);
if (!self)
if (!self) {
return DefWindowProc(hWnd, message, wParam, lParam);
}
// We want to handle IME events before the OS does any default handling.
switch (message) {
@@ -490,8 +497,9 @@ LRESULT CALLBACK OsrWindowWin::OsrWndProc(HWND hWnd,
static_cast<IAccessible*>(self->accessibility_root_));
} else {
// Notify the renderer to enable accessibility.
if (self->browser_ && self->browser_->GetHost())
if (self->browser_ && self->browser_->GetHost()) {
self->browser_->GetHost()->SetAccessibilityState(STATE_ENABLED);
}
}
}
} break;
@@ -536,8 +544,9 @@ LRESULT CALLBACK OsrWindowWin::OsrWndProc(HWND hWnd,
return 0;
case WM_ERASEBKGND:
if (self->OnEraseBkgnd())
if (self->OnEraseBkgnd()) {
break;
}
// Don't erase the background.
return 0;
@@ -546,8 +555,9 @@ LRESULT CALLBACK OsrWindowWin::OsrWndProc(HWND hWnd,
// intutive, complete and simpler to code.
// https://msdn.microsoft.com/en-us/library/hh454903(v=vs.85).aspx
case WM_TOUCH:
if (self->OnTouchEvent(message, wParam, lParam))
if (self->OnTouchEvent(message, wParam, lParam)) {
return 0;
}
break;
case WM_NCDESTROY:
@@ -561,12 +571,14 @@ LRESULT CALLBACK OsrWindowWin::OsrWndProc(HWND hWnd,
}
void OsrWindowWin::OnMouseEvent(UINT message, WPARAM wParam, LPARAM lParam) {
if (IsMouseEventFromTouch(message))
if (IsMouseEventFromTouch(message)) {
return;
}
CefRefPtr<CefBrowserHost> browser_host;
if (browser_)
if (browser_) {
browser_host = browser_->GetHost();
}
LONG currentTime = 0;
bool cancelPreviousClick = false;
@@ -635,8 +647,9 @@ void OsrWindowWin::OnMouseEvent(UINT message, WPARAM wParam, LPARAM lParam) {
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
if (GetCapture() == hwnd_)
if (GetCapture() == hwnd_) {
ReleaseCapture();
}
if (mouse_rotation_) {
// End rotation effect.
mouse_rotation_ = false;
@@ -732,8 +745,9 @@ void OsrWindowWin::OnMouseEvent(UINT message, WPARAM wParam, LPARAM lParam) {
if (browser_host) {
POINT screen_point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
HWND scrolled_wnd = ::WindowFromPoint(screen_point);
if (scrolled_wnd != hwnd_)
if (scrolled_wnd != hwnd_) {
break;
}
ScreenToClient(hwnd_, &screen_point);
int delta = GET_WHEEL_DELTA_WPARAM(wParam);
@@ -756,26 +770,31 @@ void OsrWindowWin::OnSize() {
// Keep |client_rect_| up to date.
::GetClientRect(hwnd_, &client_rect_);
if (browser_)
if (browser_) {
browser_->GetHost()->WasResized();
}
}
void OsrWindowWin::OnFocus(bool setFocus) {
if (browser_)
if (browser_) {
browser_->GetHost()->SetFocus(setFocus);
}
}
void OsrWindowWin::OnCaptureLost() {
if (mouse_rotation_)
if (mouse_rotation_) {
return;
}
if (browser_)
if (browser_) {
browser_->GetHost()->SendCaptureLostEvent();
}
}
void OsrWindowWin::OnKeyEvent(UINT message, WPARAM wParam, LPARAM lParam) {
if (!browser_)
if (!browser_) {
return;
}
CefKeyEvent event;
event.windows_key_code = wParam;
@@ -783,12 +802,13 @@ void OsrWindowWin::OnKeyEvent(UINT message, WPARAM wParam, LPARAM lParam) {
event.is_system_key = message == WM_SYSCHAR || message == WM_SYSKEYDOWN ||
message == WM_SYSKEYUP;
if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) {
event.type = KEYEVENT_RAWKEYDOWN;
else if (message == WM_KEYUP || message == WM_SYSKEYUP)
} else if (message == WM_KEYUP || message == WM_SYSKEYUP) {
event.type = KEYEVENT_KEYUP;
else
} else {
event.type = KEYEVENT_CHAR;
}
event.modifiers = GetCefKeyboardModifiers(wParam, lParam);
// mimic alt-gr check behaviour from
@@ -822,8 +842,9 @@ void OsrWindowWin::OnPaint() {
BeginPaint(hwnd_, &ps);
EndPaint(hwnd_, &ps);
if (browser_)
if (browser_) {
browser_->GetHost()->Invalidate(PET_VIEW);
}
}
bool OsrWindowWin::OnEraseBkgnd() {
@@ -835,8 +856,9 @@ bool OsrWindowWin::OnTouchEvent(UINT message, WPARAM wParam, LPARAM lParam) {
// Handle touch events on Windows.
int num_points = LOWORD(wParam);
// Chromium only supports upto 16 touch points.
if (num_points < 0 || num_points > 16)
if (num_points < 0 || num_points > 16) {
return false;
}
std::unique_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[num_points]);
if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(lParam), num_points,
input.get(), sizeof(TOUCHINPUT))) {
@@ -852,8 +874,9 @@ bool OsrWindowWin::OnTouchEvent(UINT message, WPARAM wParam, LPARAM lParam) {
// ignore touch events in the non-client area.
LPARAM l_param_ht = MAKELPARAM(point.x, point.y);
LRESULT hittest = SendMessage(hwnd_, WM_NCHITTEST, 0, l_param_ht);
if (hittest != HTCLIENT)
if (hittest != HTCLIENT) {
return false;
}
}
ScreenToClient(hwnd_, &point);
@@ -878,8 +901,9 @@ bool OsrWindowWin::OnTouchEvent(UINT message, WPARAM wParam, LPARAM lParam) {
touch_event.modifiers = 0;
// Notify the browser of touch event
if (browser_)
if (browser_) {
browser_->GetHost()->SendTouchEvent(touch_event);
}
}
CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(lParam));
return true;
@@ -889,8 +913,9 @@ bool OsrWindowWin::OnTouchEvent(UINT message, WPARAM wParam, LPARAM lParam) {
}
bool OsrWindowWin::IsOverPopupWidget(int x, int y) const {
if (!render_handler_)
if (!render_handler_) {
return false;
}
return render_handler_->IsOverPopupWidget(x, y);
}
@@ -950,12 +975,14 @@ void OsrWindowWin::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) {
rect.x = rect.y = 0;
rect.width = DeviceToLogical(client_rect_.right - client_rect_.left,
device_scale_factor_);
if (rect.width == 0)
if (rect.width == 0) {
rect.width = 1;
}
rect.height = DeviceToLogical(client_rect_.bottom - client_rect_.top,
device_scale_factor_);
if (rect.height == 0)
if (rect.height == 0) {
rect.height = 1;
}
}
bool OsrWindowWin::GetScreenPoint(CefRefPtr<CefBrowser> browser,
@@ -966,8 +993,9 @@ bool OsrWindowWin::GetScreenPoint(CefRefPtr<CefBrowser> browser,
CEF_REQUIRE_UI_THREAD();
DCHECK_GT(device_scale_factor_, 0);
if (!::IsWindow(hwnd_))
if (!::IsWindow(hwnd_)) {
return false;
}
// Convert from view DIP coordinates to screen device (pixel) coordinates.
POINT screen_pt = {LogicalToDevice(viewX, device_scale_factor_),
@@ -983,8 +1011,9 @@ bool OsrWindowWin::GetScreenInfo(CefRefPtr<CefBrowser> browser,
CEF_REQUIRE_UI_THREAD();
DCHECK_GT(device_scale_factor_, 0);
if (!::IsWindow(hwnd_))
if (!::IsWindow(hwnd_)) {
return false;
}
CefRect view_rect;
GetViewRect(browser, view_rect);
@@ -1033,8 +1062,9 @@ void OsrWindowWin::OnCursorChange(CefRefPtr<CefBrowser> browser,
const CefCursorInfo& custom_cursor_info) {
CEF_REQUIRE_UI_THREAD();
if (!::IsWindow(hwnd_))
if (!::IsWindow(hwnd_)) {
return;
}
// Change the window's cursor.
SetClassLongPtr(hwnd_, GCLP_HCURSOR,
@@ -1051,8 +1081,9 @@ bool OsrWindowWin::StartDragging(
CEF_REQUIRE_UI_THREAD();
#if defined(CEF_USE_ATL)
if (!drop_target_)
if (!drop_target_) {
return false;
}
current_drag_op_ = DRAG_OPERATION_NONE;
CefBrowserHost::DragOperationsMask result =
@@ -1153,8 +1184,9 @@ CefBrowserHost::DragOperationsMask OsrWindowWin::OnDragOver(
}
void OsrWindowWin::OnDragLeave() {
if (browser_)
if (browser_) {
browser_->GetHost()->DragTargetDragLeave();
}
}
CefBrowserHost::DragOperationsMask OsrWindowWin::OnDrop(

View File

@@ -54,8 +54,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (!test_runner::IsTestURL(url, kTestUrlPath))
if (!test_runner::IsTestURL(url, kTestUrlPath)) {
return false;
}
// Parse |request| as a JSON dictionary.
CefRefPtr<CefDictionaryValue> request_dict = ParseJSON(request);
@@ -65,16 +66,18 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
}
// Verify the "name" key.
if (!VerifyKey(request_dict, kNameKey, VTYPE_STRING, callback))
if (!VerifyKey(request_dict, kNameKey, VTYPE_STRING, callback)) {
return true;
}
const std::string& message_name = request_dict->GetString(kNameKey);
if (message_name == kNameValueGet) {
// JavaScript is requesting a JSON representation of the preferences tree.
// Verify the "include_defaults" key.
if (!VerifyKey(request_dict, kIncludeDefaultsKey, VTYPE_BOOL, callback))
if (!VerifyKey(request_dict, kIncludeDefaultsKey, VTYPE_BOOL, callback)) {
return true;
}
const bool include_defaults = request_dict->GetBool(kIncludeDefaultsKey);
@@ -86,8 +89,10 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// specified JSON representation.
// Verify the "preferences" key.
if (!VerifyKey(request_dict, kPreferencesKey, VTYPE_DICTIONARY, callback))
if (!VerifyKey(request_dict, kPreferencesKey, VTYPE_DICTIONARY,
callback)) {
return true;
}
CefRefPtr<CefDictionaryValue> preferences =
request_dict->GetDictionary(kPreferencesKey);
@@ -147,30 +152,34 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
ss << "Successfully changed " << changed_names.size() << " preferences; ";
for (size_t i = 0; i < changed_names.size(); ++i) {
ss << changed_names[i];
if (i < changed_names.size() - 1)
if (i < changed_names.size() - 1) {
ss << ", ";
}
}
message = ss.str();
}
if (!success) {
DCHECK(!error.empty());
if (!message.empty())
if (!message.empty()) {
message += "\n";
}
message += error;
}
if (changed_names.empty()) {
if (!message.empty())
if (!message.empty()) {
message += "\n";
}
message += "No preferences changed.";
}
// Return the message to the JavaScript caller.
if (success)
if (success) {
callback->Success(message);
else
} else {
callback->Failure(kPreferenceApplicationError, message);
}
}
// Execute |callback| with the global state dictionary as a JSON string.
@@ -206,8 +215,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Convert a JSON string to a dictionary value.
static CefRefPtr<CefDictionaryValue> ParseJSON(const CefString& string) {
CefRefPtr<CefValue> value = CefParseJSON(string, JSON_PARSER_RFC);
if (value.get() && value->GetType() == VTYPE_DICTIONARY)
if (value.get() && value->GetType() == VTYPE_DICTIONARY) {
return value->GetDictionary();
}
return nullptr;
}
@@ -288,10 +298,11 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
const std::string& string_val = value->GetString();
switch (existing_value->GetType()) {
case VTYPE_BOOL:
if (string_val == "true" || string_val == "1")
if (string_val == "true" || string_val == "1") {
value->SetBool(true);
else if (string_val == "false" || string_val == "0")
} else if (string_val == "false" || string_val == "0") {
value->SetBool(false);
}
break;
case VTYPE_INT:
value->SetInt(atoi(string_val.c_str()));
@@ -306,8 +317,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
}
// Nothing to do if the value hasn't changed.
if (existing_value->IsEqual(value))
if (existing_value->IsEqual(value)) {
return true;
}
// Attempt to set the preference.
CefString error_str;

View File

@@ -87,8 +87,9 @@ class StickyPrintSettingGtk {
// Lazily initialize the singleton instance.
StickyPrintSettingGtk* GetLastUsedSettings() {
static StickyPrintSettingGtk* settings = nullptr;
if (!settings)
if (!settings) {
settings = new StickyPrintSettingGtk();
}
return settings;
}
@@ -114,8 +115,9 @@ class GtkPrinterList {
// - Printer list out of sync with printer dialog UI.
// - Querying for non-existant printers like 'Print to PDF'.
GtkPrinter* GetPrinterWithName(const std::string& name) {
if (name.empty())
if (name.empty()) {
return nullptr;
}
for (std::vector<GtkPrinter*>::iterator it = printers_.begin();
it < printers_.end(); ++it) {
@@ -131,8 +133,9 @@ class GtkPrinterList {
// Callback function used by gtk_enumerate_printers() to get all printer.
static gboolean SetPrinter(GtkPrinter* printer, gpointer data) {
GtkPrinterList* printer_list = reinterpret_cast<GtkPrinterList*>(data);
if (gtk_printer_is_default(printer))
if (gtk_printer_is_default(printer)) {
printer_list->default_printer_ = printer;
}
g_object_ref(printer);
printer_list->printers_.push_back(printer);
@@ -226,8 +229,9 @@ void InitPrintSettings(GtkPrintSettings* settings,
std::string device_name;
const gchar* name = gtk_print_settings_get_printer(settings);
if (name)
if (name) {
device_name = name;
}
print_settings->SetDeviceName(device_name);
CefSize physical_size_device_units;
@@ -278,8 +282,9 @@ void InitPrintSettings(GtkPrintSettings* settings,
GtkWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
scoped_refptr<RootWindow> root_window =
RootWindow::GetForBrowser(browser->GetIdentifier());
if (root_window)
if (root_window) {
return GTK_WINDOW(root_window->GetWindowHandle());
}
return nullptr;
}
@@ -386,8 +391,9 @@ struct ClientPrintHandlerGtk::PrintHandler {
gtk_print_settings_set(gtk_settings_, kCUPSDuplex, cups_duplex_mode);
}
if (!page_setup_)
if (!page_setup_) {
page_setup_ = gtk_page_setup_new();
}
gtk_print_settings_set_orientation(gtk_settings_,
settings->IsLandscape()
@@ -441,8 +447,9 @@ struct ClientPrintHandlerGtk::PrintHandler {
CefRefPtr<CefPrintJobCallback> callback) {
// If |printer_| is nullptr then somehow the GTK printer list changed out
// under us. In which case, just bail out.
if (!printer_)
if (!printer_) {
return false;
}
ScopedGdkThreadsEnter scoped_gdk_threads;
@@ -470,19 +477,22 @@ struct ClientPrintHandlerGtk::PrintHandler {
switch (response_id) {
case GTK_RESPONSE_OK: {
if (gtk_settings_)
if (gtk_settings_) {
g_object_unref(gtk_settings_);
}
gtk_settings_ =
gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(dialog_));
if (printer_)
if (printer_) {
g_object_unref(printer_);
}
printer_ = gtk_print_unix_dialog_get_selected_printer(
GTK_PRINT_UNIX_DIALOG(dialog_));
g_object_ref(printer_);
if (page_setup_)
if (page_setup_) {
g_object_unref(page_setup_);
}
page_setup_ = gtk_print_unix_dialog_get_page_setup(
GTK_PRINT_UNIX_DIALOG(dialog_));
g_object_ref(page_setup_);

View File

@@ -16,15 +16,17 @@ bool GetResourceDir(std::string& dir) {
// Retrieve the executable path.
ssize_t len = readlink("/proc/self/exe", buff, sizeof(buff) - 1);
if (len == -1)
if (len == -1) {
return false;
}
buff[len] = 0;
// Remove the executable name from the path.
char* pos = strrchr(buff, '/');
if (!pos)
if (!pos) {
return false;
}
// Add "cefclient_files" to the path.
strcpy(pos + 1, "cefclient_files");

View File

@@ -49,8 +49,9 @@ int GetResourceId(const char* resource_name) {
{"xmlhttprequest.html", IDS_XMLHTTPREQUEST_HTML}};
for (size_t i = 0; i < sizeof(resource_map) / sizeof(_resource_map); ++i) {
if (!strcmp(resource_map[i].name, resource_name))
if (!strcmp(resource_map[i].name, resource_name)) {
return resource_map[i].id;
}
}
return 0;

View File

@@ -43,8 +43,9 @@ class FindReplaceResponseFilter : public CefResponseFilter {
// Determine a reasonable amount of space for find/replace overflow. For
// example, the amount of space required if the search string is
// found/replaced 10 times (plus space for the count).
if (replace_size > find_size)
if (replace_size > find_size) {
replace_overflow_size_ = (replace_size - find_size + 3) * 10;
}
return true;
}
@@ -195,8 +196,9 @@ class PassThruResponseFilter : public CefResponseFilter {
// Write out the contents unchanged.
data_out_written = std::min(data_in_read, data_out_size);
if (data_out_written > 0)
if (data_out_written > 0) {
memcpy(data_out, data_in, data_out_written);
}
return RESPONSE_FILTER_DONE;
}
@@ -228,11 +230,13 @@ CefRefPtr<CefResponseFilter> GetResourceResponseFilter(
// Use the find/replace filter on the test URL.
const std::string& url = request->GetURL();
if (test_runner::IsTestURL(url, kTestUrlPath))
if (test_runner::IsTestURL(url, kTestUrlPath)) {
return new FindReplaceResponseFilter();
}
if (MatchesFilterURL(url))
if (MatchesFilterURL(url)) {
return new PassThruResponseFilter();
}
return nullptr;
}

View File

@@ -28,8 +28,9 @@ void RootWindow::OnExtensionsChanged(const ExtensionSet& extensions) {
DCHECK(delegate_);
DCHECK(!WithExtension());
if (extensions.empty())
if (extensions.empty()) {
return;
}
ExtensionSet::const_iterator it = extensions.begin();
for (; it != extensions.end(); ++it) {

View File

@@ -40,8 +40,9 @@ void UseDefaultX11VisualForGtk(GtkWidget* widget) {
GList* visuals = gdk_screen_list_visuals(screen);
GdkX11Screen* x11_screen = GDK_X11_SCREEN(screen);
if (x11_screen == nullptr)
if (x11_screen == nullptr) {
return;
}
Visual* default_xvisual = DefaultVisual(GDK_SCREEN_XDISPLAY(x11_screen),
GDK_SCREEN_XNUMBER(x11_screen));
@@ -67,8 +68,9 @@ bool IsWindowMaximized(GtkWindow* window) {
void MinimizeWindow(GtkWindow* window) {
// Unmaximize the window before minimizing so restore behaves correctly.
if (IsWindowMaximized(window))
if (IsWindowMaximized(window)) {
gtk_window_unmaximize(window);
}
gtk_window_iconify(window);
}
@@ -144,14 +146,18 @@ void RootWindowGtk::InitAsPopup(RootWindow::Delegate* delegate,
with_osr_ = with_osr;
is_popup_ = true;
if (popupFeatures.xSet)
if (popupFeatures.xSet) {
start_rect_.x = popupFeatures.x;
if (popupFeatures.ySet)
}
if (popupFeatures.ySet) {
start_rect_.y = popupFeatures.y;
if (popupFeatures.widthSet)
}
if (popupFeatures.widthSet) {
start_rect_.width = popupFeatures.width;
if (popupFeatures.heightSet)
}
if (popupFeatures.heightSet) {
start_rect_.height = popupFeatures.height;
}
CreateBrowserWindow(std::string());
@@ -167,8 +173,9 @@ void RootWindowGtk::InitAsPopup(RootWindow::Delegate* delegate,
void RootWindowGtk::Show(ShowMode mode) {
REQUIRE_MAIN_THREAD();
if (!window_)
if (!window_) {
return;
}
ScopedGdkThreadsEnter scoped_gdk_threads;
@@ -176,10 +183,11 @@ void RootWindowGtk::Show(ShowMode mode) {
UseDefaultX11VisualForGtk(GTK_WIDGET(window_));
gtk_widget_show_all(window_);
if (mode == ShowMinimized)
if (mode == ShowMinimized) {
MinimizeWindow(GTK_WINDOW(window_));
else if (mode == ShowMaximized)
} else if (mode == ShowMaximized) {
MaximizeWindow(GTK_WINDOW(window_));
}
// Flush the display to make sure the underlying X11 window gets created
// immediately.
@@ -193,15 +201,17 @@ void RootWindowGtk::Hide() {
ScopedGdkThreadsEnter scoped_gdk_threads;
if (window_)
if (window_) {
gtk_widget_hide(window_);
}
}
void RootWindowGtk::SetBounds(int x, int y, size_t width, size_t height) {
REQUIRE_MAIN_THREAD();
if (!window_)
if (!window_) {
return;
}
ScopedGdkThreadsEnter scoped_gdk_threads;
@@ -209,10 +219,11 @@ void RootWindowGtk::SetBounds(int x, int y, size_t width, size_t height) {
GdkWindow* gdk_window = gtk_widget_get_window(window_);
// Make sure the window isn't minimized or maximized.
if (IsWindowMaximized(window))
if (IsWindowMaximized(window)) {
gtk_window_unmaximize(window);
else
} else {
gtk_window_present(window);
}
gdk_window_move_resize(gdk_window, x, y, width, height);
}
@@ -233,15 +244,17 @@ void RootWindowGtk::Close(bool force) {
void RootWindowGtk::SetDeviceScaleFactor(float device_scale_factor) {
REQUIRE_MAIN_THREAD();
if (browser_window_ && with_osr_)
if (browser_window_ && with_osr_) {
browser_window_->SetDeviceScaleFactor(device_scale_factor);
}
}
float RootWindowGtk::GetDeviceScaleFactor() const {
REQUIRE_MAIN_THREAD();
if (browser_window_ && with_osr_)
if (browser_window_ && with_osr_) {
return browser_window_->GetDeviceScaleFactor();
}
NOTREACHED();
return 0.0f;
@@ -250,8 +263,9 @@ float RootWindowGtk::GetDeviceScaleFactor() const {
CefRefPtr<CefBrowser> RootWindowGtk::GetBrowser() const {
REQUIRE_MAIN_THREAD();
if (browser_window_)
if (browser_window_) {
return browser_window_->GetBrowser();
}
return nullptr;
}
@@ -443,8 +457,9 @@ void RootWindowGtk::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
// For popup browsers create the root window once the browser has been
// created.
if (is_popup_)
if (is_popup_) {
CreateRootWindow(CefBrowserSettings(), false);
}
delegate_->OnBrowserCreated(this, browser);
}
@@ -503,18 +518,20 @@ void RootWindowGtk::OnSetFullscreen(bool fullscreen) {
if (browser) {
std::unique_ptr<window_test::WindowTestRunnerGtk> test_runner(
new window_test::WindowTestRunnerGtk());
if (fullscreen)
if (fullscreen) {
test_runner->Maximize(browser);
else
} else {
test_runner->Restore(browser);
}
}
}
void RootWindowGtk::OnAutoResize(const CefSize& new_size) {
REQUIRE_MAIN_THREAD();
if (!window_)
if (!window_) {
return;
}
ScopedGdkThreadsEnter scoped_gdk_threads;
@@ -522,10 +539,11 @@ void RootWindowGtk::OnAutoResize(const CefSize& new_size) {
GdkWindow* gdk_window = gtk_widget_get_window(window_);
// Make sure the window isn't minimized or maximized.
if (IsWindowMaximized(window))
if (IsWindowMaximized(window)) {
gtk_window_unmaximize(window);
else
} else {
gtk_window_present(window);
}
gdk_window_resize(gdk_window, new_size.width, new_size.height);
}
@@ -575,8 +593,9 @@ void RootWindowGtk::NotifySetFocus() {
return;
}
if (!browser_window_.get())
if (!browser_window_.get()) {
return;
}
browser_window_->SetFocus(true);
delegate_->OnRootWindowActivated(this);
@@ -589,13 +608,15 @@ void RootWindowGtk::NotifyVisibilityChange(bool show) {
return;
}
if (!browser_window_.get())
if (!browser_window_.get()) {
return;
}
if (show)
if (show) {
browser_window_->Show();
else
} else {
browser_window_->Hide();
}
}
void RootWindowGtk::NotifyMenuBarHeight(int height) {
@@ -652,8 +673,9 @@ void RootWindowGtk::NotifyButtonClicked(int id) {
}
CefRefPtr<CefBrowser> browser = GetBrowser();
if (!browser.get())
if (!browser.get()) {
return;
}
switch (id) {
case IDC_NAV_BACK:
@@ -680,8 +702,9 @@ void RootWindowGtk::NotifyMenuItem(int id) {
}
// Run the test.
if (delegate_)
if (delegate_) {
delegate_->OnTest(this, id);
}
}
void RootWindowGtk::NotifyForceClose() {
@@ -717,14 +740,17 @@ void RootWindowGtk::NotifyDestroyedIfDone(bool window_destroyed,
return;
}
if (window_destroyed)
if (window_destroyed) {
window_destroyed_ = true;
if (browser_destroyed)
}
if (browser_destroyed) {
browser_destroyed_ = true;
}
// Notify once both the window and the browser have been destroyed.
if (window_destroyed_ && browser_destroyed_)
if (window_destroyed_ && browser_destroyed_) {
delegate_->OnRootWindowDestroyed(this);
}
}
// static
@@ -781,8 +807,9 @@ gboolean RootWindowGtk::WindowDelete(GtkWidget* widget,
REQUIRE_MAIN_THREAD();
// Called to query whether the root window should be closed.
if (self->force_close_)
if (self->force_close_) {
return FALSE; // Allow the close.
}
if (!self->is_closing_) {
// Notify the browser window that we would like to close it. This
@@ -886,8 +913,9 @@ gboolean RootWindowGtk::URLEntryButtonPress(GtkWidget* widget,
Atom atoms[2];
int result =
XInternAtoms(xdisplay, const_cast<char**>(kAtoms), 2, false, atoms);
if (!result)
if (!result) {
NOTREACHED();
}
XEvent e;
e.type = ClientMessage;

View File

@@ -74,8 +74,9 @@ std::optional<CefRect> GetWindowBoundsInScreen(NSWindow* window) {
}
auto screen = [window screen];
if (screen == nil)
if (screen == nil) {
screen = [NSScreen mainScreen];
}
const auto bounds = [window frame];
const auto screen_bounds = [screen frame];
@@ -315,14 +316,18 @@ void RootWindowMacImpl::InitAsPopup(RootWindow::Delegate* delegate,
with_osr_ = with_osr;
is_popup_ = true;
if (popupFeatures.xSet)
if (popupFeatures.xSet) {
initial_bounds_.x = popupFeatures.x;
if (popupFeatures.ySet)
}
if (popupFeatures.ySet) {
initial_bounds_.y = popupFeatures.y;
if (popupFeatures.widthSet)
}
if (popupFeatures.widthSet) {
initial_bounds_.width = popupFeatures.width;
if (popupFeatures.heightSet)
}
if (popupFeatures.heightSet) {
initial_bounds_.height = popupFeatures.height;
}
CreateBrowserWindow(std::string());
@@ -338,8 +343,9 @@ void RootWindowMacImpl::InitAsPopup(RootWindow::Delegate* delegate,
void RootWindowMacImpl::Show(RootWindow::ShowMode mode) {
REQUIRE_MAIN_THREAD();
if (!window_)
if (!window_) {
return;
}
const bool is_visible = [window_ isVisible];
const bool is_minimized = [window_ isMiniaturized];
@@ -353,31 +359,36 @@ void RootWindowMacImpl::Show(RootWindow::ShowMode mode) {
}
// Undo the previous state since it's not the desired state.
if (is_minimized)
if (is_minimized) {
[window_ deminiaturize:nil];
else if (is_maximized)
} else if (is_maximized) {
[window_ performZoom:nil];
}
// Window visibility may change after (for example) deminiaturizing the
// window.
if (![window_ isVisible])
if (![window_ isVisible]) {
[window_ makeKeyAndOrderFront:nil];
}
if (mode == RootWindow::ShowMinimized)
if (mode == RootWindow::ShowMinimized) {
[window_ performMiniaturize:nil];
else if (mode == RootWindow::ShowMaximized)
} else if (mode == RootWindow::ShowMaximized) {
[window_ performZoom:nil];
}
}
void RootWindowMacImpl::Hide() {
REQUIRE_MAIN_THREAD();
if (!window_)
if (!window_) {
return;
}
// Undo miniaturization, if any, so the window will actually be hidden.
if ([window_ isMiniaturized])
if ([window_ isMiniaturized]) {
[window_ deminiaturize:nil];
}
// Hide the window.
[window_ orderOut:nil];
@@ -386,8 +397,9 @@ void RootWindowMacImpl::Hide() {
void RootWindowMacImpl::SetBounds(int x, int y, size_t width, size_t height) {
REQUIRE_MAIN_THREAD();
if (!window_)
if (!window_) {
return;
}
const CefRect dip_bounds(x, y, static_cast<int>(width),
static_cast<int>(height));
@@ -413,15 +425,17 @@ void RootWindowMacImpl::Close(bool force) {
void RootWindowMacImpl::SetDeviceScaleFactor(float device_scale_factor) {
REQUIRE_MAIN_THREAD();
if (browser_window_ && with_osr_)
if (browser_window_ && with_osr_) {
browser_window_->SetDeviceScaleFactor(device_scale_factor);
}
}
float RootWindowMacImpl::GetDeviceScaleFactor() const {
REQUIRE_MAIN_THREAD();
if (browser_window_ && with_osr_)
if (browser_window_ && with_osr_) {
return browser_window_->GetDeviceScaleFactor();
}
NOTREACHED();
return 0.0f;
@@ -430,8 +444,9 @@ float RootWindowMacImpl::GetDeviceScaleFactor() const {
CefRefPtr<CefBrowser> RootWindowMacImpl::GetBrowser() const {
REQUIRE_MAIN_THREAD();
if (browser_window_)
if (browser_window_) {
return browser_window_->GetBrowser();
}
return nullptr;
}
@@ -478,10 +493,12 @@ void RootWindowMacImpl::CreateRootWindow(const CefBrowserSettings& settings,
CefRect dip_bounds = initial_bounds_;
// TODO(port): Also, maybe there's a better way to choose the default size.
if (dip_bounds.width <= 0)
if (dip_bounds.width <= 0) {
dip_bounds.width = 800;
if (dip_bounds.height <= 0)
}
if (dip_bounds.height <= 0) {
dip_bounds.height = 600;
}
// For popups, the requested bounds are for the content area and the requested
// origin is for the window.
@@ -636,8 +653,9 @@ void RootWindowMacImpl::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
// For popup browsers create the root window once the browser has been
// created.
if (is_popup_)
if (is_popup_) {
CreateRootWindow(CefBrowserSettings(), false);
}
root_window_.delegate_->OnBrowserCreated(&root_window_, browser);
}
@@ -691,18 +709,20 @@ void RootWindowMacImpl::OnSetFullscreen(bool fullscreen) {
if (browser) {
std::unique_ptr<window_test::WindowTestRunnerMac> test_runner(
new window_test::WindowTestRunnerMac());
if (fullscreen)
if (fullscreen) {
test_runner->Maximize(browser);
else
} else {
test_runner->Restore(browser);
}
}
}
void RootWindowMacImpl::OnAutoResize(const CefSize& new_size) {
REQUIRE_MAIN_THREAD();
if (!window_)
if (!window_) {
return;
}
// Desired content rectangle.
NSRect content_rect;
@@ -750,8 +770,9 @@ void RootWindowMacImpl::OnSetLoadingState(bool isLoading,
void RootWindowMacImpl::NotifyDestroyedIfDone() {
// Notify once both the window and the browser have been destroyed.
if (window_destroyed_ && browser_destroyed_)
if (window_destroyed_ && browser_destroyed_) {
root_window_.delegate_->OnRootWindowDestroyed(&root_window_);
}
}
RootWindowMac::RootWindowMac() {
@@ -908,40 +929,46 @@ void RootWindowMac::OnNativeWindowClosed() {
- (IBAction)goBack:(id)sender {
CefRefPtr<CefBrowser> browser = root_window_->GetBrowser();
if (browser.get())
if (browser.get()) {
browser->GoBack();
}
}
- (IBAction)goForward:(id)sender {
CefRefPtr<CefBrowser> browser = root_window_->GetBrowser();
if (browser.get())
if (browser.get()) {
browser->GoForward();
}
}
- (IBAction)reload:(id)sender {
CefRefPtr<CefBrowser> browser = root_window_->GetBrowser();
if (browser.get())
if (browser.get()) {
browser->Reload();
}
}
- (IBAction)stopLoading:(id)sender {
CefRefPtr<CefBrowser> browser = root_window_->GetBrowser();
if (browser.get())
if (browser.get()) {
browser->StopLoad();
}
}
- (IBAction)takeURLStringValueFrom:(NSTextField*)sender {
CefRefPtr<CefBrowser> browser = root_window_->GetBrowser();
if (!browser.get())
if (!browser.get()) {
return;
}
NSString* url = [sender stringValue];
// if it doesn't already have a prefix, add http. If we can't parse it,
// just don't bother rather than making things worse.
NSURL* tempUrl = [NSURL URLWithString:url];
if (tempUrl && ![tempUrl scheme])
if (tempUrl && ![tempUrl scheme]) {
url = [@"http://" stringByAppendingString:url];
}
std::string urlStr = [url UTF8String];
browser->GetMainFrame()->LoadURL(urlStr);
@@ -950,30 +977,34 @@ void RootWindowMac::OnNativeWindowClosed() {
// Called when we are activated (when we gain focus).
- (void)windowDidBecomeKey:(NSNotification*)notification {
client::BrowserWindow* browser_window = root_window_->browser_window();
if (browser_window)
if (browser_window) {
browser_window->SetFocus(true);
}
root_window_->delegate()->OnRootWindowActivated(root_window_);
}
// Called when we are deactivated (when we lose focus).
- (void)windowDidResignKey:(NSNotification*)notification {
client::BrowserWindow* browser_window = root_window_->browser_window();
if (browser_window)
if (browser_window) {
browser_window->SetFocus(false);
}
}
// Called when we have been minimized.
- (void)windowDidMiniaturize:(NSNotification*)notification {
client::BrowserWindow* browser_window = root_window_->browser_window();
if (browser_window)
if (browser_window) {
browser_window->Hide();
}
}
// Called when we have been unminimized.
- (void)windowDidDeminiaturize:(NSNotification*)notification {
client::BrowserWindow* browser_window = root_window_->browser_window();
if (browser_window)
if (browser_window) {
browser_window->Show();
}
}
// Called when we have been resized.
@@ -999,8 +1030,9 @@ void RootWindowMac::OnNativeWindowClosed() {
// If the window is miniaturized then nothing has really changed.
if (![window_ isMiniaturized]) {
client::BrowserWindow* browser_window = root_window_->browser_window();
if (browser_window)
if (browser_window) {
browser_window->Hide();
}
}
}
@@ -1009,8 +1041,9 @@ void RootWindowMac::OnNativeWindowClosed() {
// If the window is miniaturized then nothing has really changed.
if (![window_ isMiniaturized]) {
client::BrowserWindow* browser_window = root_window_->browser_window();
if (browser_window)
if (browser_window) {
browser_window->Show();
}
}
}

View File

@@ -52,8 +52,9 @@ class ClientRequestContextHandler : public CefRequestContextHandler,
std::string part;
std::istringstream f(extension_path);
while (getline(f, part, ';')) {
if (!part.empty())
if (!part.empty()) {
extension_util::LoadExtension(request_context, part, this);
}
}
}
}
@@ -190,18 +191,21 @@ bool RootWindowManager::HasRootWindowAsExtension(
REQUIRE_MAIN_THREAD();
for (auto root_window : root_windows_) {
if (!root_window->WithExtension())
if (!root_window->WithExtension()) {
continue;
}
CefRefPtr<CefBrowser> browser = root_window->GetBrowser();
if (!browser)
if (!browser) {
continue;
}
CefRefPtr<CefExtension> browser_extension =
browser->GetHost()->GetExtension();
DCHECK(browser_extension);
if (browser_extension->GetIdentifier() == extension->GetIdentifier())
if (browser_extension->GetIdentifier() == extension->GetIdentifier()) {
return true;
}
}
return false;
@@ -213,8 +217,9 @@ scoped_refptr<RootWindow> RootWindowManager::GetWindowForBrowser(
for (auto root_window : root_windows_) {
CefRefPtr<CefBrowser> browser = root_window->GetBrowser();
if (browser.get() && browser->GetIdentifier() == browser_id)
if (browser.get() && browser->GetIdentifier() == browser_id) {
return root_window;
}
}
return nullptr;
}
@@ -237,8 +242,9 @@ void RootWindowManager::CloseAllWindows(bool force) {
return;
}
if (root_windows_.empty())
if (root_windows_.empty()) {
return;
}
// Use a copy of |root_windows_| because the original set may be modified
// in OnRootWindowDestroyed while iterating.
@@ -258,14 +264,16 @@ void RootWindowManager::AddExtension(CefRefPtr<CefExtension> extension) {
}
// Don't track extensions that can't be loaded directly.
if (extension_util::GetExtensionURL(extension).empty())
if (extension_util::GetExtensionURL(extension).empty()) {
return;
}
// Don't add the same extension multiple times.
ExtensionSet::const_iterator it = extensions_.begin();
for (; it != extensions_.end(); ++it) {
if ((*it)->GetIdentifier() == extension->GetIdentifier())
if ((*it)->GetIdentifier() == extension->GetIdentifier()) {
return;
}
}
extensions_.insert(extension);
@@ -297,8 +305,9 @@ void RootWindowManager::NotifyExtensionsChanged() {
REQUIRE_MAIN_THREAD();
for (auto root_window : root_windows_) {
if (!root_window->WithExtension())
if (!root_window->WithExtension()) {
root_window->OnExtensionsChanged(extensions_);
}
}
}
@@ -366,8 +375,9 @@ void RootWindowManager::OnRootWindowDestroyed(RootWindow* root_window) {
RootWindowSet::iterator it = root_windows_.find(root_window);
DCHECK(it != root_windows_.end());
if (it != root_windows_.end())
if (it != root_windows_.end()) {
root_windows_.erase(it);
}
if (root_window == active_root_window_) {
active_root_window_ = nullptr;
@@ -391,8 +401,9 @@ void RootWindowManager::OnRootWindowActivated(RootWindow* root_window) {
return;
}
if (root_window == active_root_window_)
if (root_window == active_root_window_) {
return;
}
active_root_window_ = root_window;

View File

@@ -62,14 +62,18 @@ void RootWindowViews::InitAsPopup(RootWindow::Delegate* delegate,
config_ = std::make_unique<RootWindowConfig>();
config_->with_controls = with_controls;
if (popupFeatures.xSet)
if (popupFeatures.xSet) {
initial_bounds_.x = popupFeatures.x;
if (popupFeatures.ySet)
}
if (popupFeatures.ySet) {
initial_bounds_.y = popupFeatures.y;
if (popupFeatures.widthSet)
}
if (popupFeatures.widthSet) {
initial_bounds_.width = popupFeatures.width;
if (popupFeatures.heightSet)
}
if (popupFeatures.heightSet) {
initial_bounds_.height = popupFeatures.height;
}
CreateClientHandler(std::string());
initialized_ = true;
@@ -85,8 +89,9 @@ void RootWindowViews::Show(ShowMode mode) {
return;
}
if (!window_)
if (!window_) {
return;
}
window_->Show();
@@ -109,8 +114,9 @@ void RootWindowViews::Hide() {
return;
}
if (window_)
if (window_) {
window_->Hide();
}
}
void RootWindowViews::SetBounds(int x, int y, size_t width, size_t height) {
@@ -134,8 +140,9 @@ void RootWindowViews::Close(bool force) {
return;
}
if (window_)
if (window_) {
window_->Close(force);
}
}
void RootWindowViews::SetDeviceScaleFactor(float device_scale_factor) {
@@ -162,8 +169,9 @@ ClientWindowHandle RootWindowViews::GetWindowHandle() const {
// ClientWindowHandle is a GtkWidget* on Linux and we don't have one of those.
return nullptr;
#else
if (browser_)
if (browser_) {
return browser_->GetHost()->GetWindowHandle();
}
return kNullWindowHandle;
#endif
}
@@ -351,8 +359,9 @@ void RootWindowViews::OnSetAddress(const std::string& url) {
return;
}
if (window_)
if (window_) {
window_->SetAddress(url);
}
}
void RootWindowViews::OnSetTitle(const std::string& title) {
@@ -363,8 +372,9 @@ void RootWindowViews::OnSetTitle(const std::string& title) {
return;
}
if (window_)
if (window_) {
window_->SetTitle(title);
}
}
void RootWindowViews::OnSetFavicon(CefRefPtr<CefImage> image) {
@@ -375,8 +385,9 @@ void RootWindowViews::OnSetFavicon(CefRefPtr<CefImage> image) {
return;
}
if (window_)
if (window_) {
window_->SetFavicon(image);
}
}
void RootWindowViews::OnSetFullscreen(bool fullscreen) {
@@ -387,8 +398,9 @@ void RootWindowViews::OnSetFullscreen(bool fullscreen) {
return;
}
if (window_)
if (window_) {
window_->SetFullscreen(fullscreen);
}
}
void RootWindowViews::OnAutoResize(const CefSize& new_size) {
@@ -449,8 +461,9 @@ void RootWindowViews::OnSetDraggableRegions(
return;
}
if (window_)
if (window_) {
window_->SetDraggableRegions(regions);
}
}
void RootWindowViews::OnTakeFocus(bool next) {
@@ -461,14 +474,16 @@ void RootWindowViews::OnTakeFocus(bool next) {
return;
}
if (window_)
if (window_) {
window_->TakeFocus(next);
}
}
void RootWindowViews::OnBeforeContextMenu(CefRefPtr<CefMenuModel> model) {
CEF_REQUIRE_UI_THREAD();
if (window_)
if (window_) {
window_->OnBeforeContextMenu(model);
}
}
void RootWindowViews::CreateClientHandler(const std::string& url) {
@@ -510,8 +525,9 @@ void RootWindowViews::InitOnUIThread(
// Populate the default image cache.
ImageCache::ImageInfoSet image_set;
for (size_t i = 0U; i < std::size(kDefaultImageCache); ++i)
for (size_t i = 0U; i < std::size(kDefaultImageCache); ++i) {
image_set.push_back(ImageCache::ImageInfo::Create2x(kDefaultImageCache[i]));
}
image_cache_->LoadImages(
image_set, base::BindOnce(&RootWindowViews::CreateViewsWindow, this,
@@ -557,8 +573,9 @@ void RootWindowViews::NotifyDestroyedIfDone() {
scoped_refptr<RootWindow> self = this;
delegate_->OnRootWindowDestroyed(this);
if (!config_->close_callback.is_null())
if (!config_->close_callback.is_null()) {
std::move(config_->close_callback).Run();
}
}
}

View File

@@ -72,8 +72,9 @@ bool IsProcessPerMonitorDpiAware() {
if (func_ptr) {
PROCESS_DPI_AWARENESS awareness;
if (SUCCEEDED(func_ptr(nullptr, &awareness)) &&
awareness == PROCESS_PER_MONITOR_DPI_AWARE)
awareness == PROCESS_PER_MONITOR_DPI_AWARE) {
per_monitor_dpi_aware = PerMonitorDpiAware::PER_MONITOR_DPI_AWARE;
}
}
}
}
@@ -88,8 +89,9 @@ float GetWindowScaleFactor(HWND hwnd) {
typedef UINT(WINAPI * GetDpiForWindowPtr)(HWND);
static GetDpiForWindowPtr func_ptr = reinterpret_cast<GetDpiForWindowPtr>(
GetProcAddress(GetModuleHandle(L"user32.dll"), "GetDpiForWindow"));
if (func_ptr)
if (func_ptr) {
return static_cast<float>(func_ptr(hwnd)) / DPI_1X;
}
}
return client::GetDeviceScaleFactor();
@@ -193,14 +195,18 @@ void RootWindowWin::InitAsPopup(RootWindow::Delegate* delegate,
with_osr_ = with_osr;
is_popup_ = true;
if (popupFeatures.xSet)
if (popupFeatures.xSet) {
initial_bounds_.x = popupFeatures.x;
if (popupFeatures.ySet)
}
if (popupFeatures.ySet) {
initial_bounds_.y = popupFeatures.y;
if (popupFeatures.widthSet)
}
if (popupFeatures.widthSet) {
initial_bounds_.width = popupFeatures.width;
if (popupFeatures.heightSet)
}
if (popupFeatures.heightSet) {
initial_bounds_.height = popupFeatures.height;
}
CreateBrowserWindow(std::string());
@@ -216,8 +222,9 @@ void RootWindowWin::InitAsPopup(RootWindow::Delegate* delegate,
void RootWindowWin::Show(ShowMode mode) {
REQUIRE_MAIN_THREAD();
if (!hwnd_)
if (!hwnd_) {
return;
}
int nCmdShow = SW_SHOWNORMAL;
switch (mode) {
@@ -235,15 +242,17 @@ void RootWindowWin::Show(ShowMode mode) {
}
ShowWindow(hwnd_, nCmdShow);
if (mode != ShowMinimized)
if (mode != ShowMinimized) {
UpdateWindow(hwnd_);
}
}
void RootWindowWin::Hide() {
REQUIRE_MAIN_THREAD();
if (hwnd_)
if (hwnd_) {
ShowWindow(hwnd_, SW_HIDE);
}
}
void RootWindowWin::SetBounds(int x, int y, size_t width, size_t height) {
@@ -259,25 +268,28 @@ void RootWindowWin::Close(bool force) {
REQUIRE_MAIN_THREAD();
if (hwnd_) {
if (force)
if (force) {
DestroyWindow(hwnd_);
else
} else {
PostMessage(hwnd_, WM_CLOSE, 0, 0);
}
}
}
void RootWindowWin::SetDeviceScaleFactor(float device_scale_factor) {
REQUIRE_MAIN_THREAD();
if (browser_window_ && with_osr_)
if (browser_window_ && with_osr_) {
browser_window_->SetDeviceScaleFactor(device_scale_factor);
}
}
float RootWindowWin::GetDeviceScaleFactor() const {
REQUIRE_MAIN_THREAD();
if (browser_window_ && with_osr_)
if (browser_window_ && with_osr_) {
return browser_window_->GetDeviceScaleFactor();
}
NOTREACHED();
return 0.0f;
@@ -286,8 +298,9 @@ float RootWindowWin::GetDeviceScaleFactor() const {
CefRefPtr<CefBrowser> RootWindowWin::GetBrowser() const {
REQUIRE_MAIN_THREAD();
if (browser_window_)
if (browser_window_) {
return browser_window_->GetBrowser();
}
return nullptr;
}
@@ -393,8 +406,9 @@ void RootWindowWin::CreateRootWindow(const CefBrowserSettings& settings,
static EnableChildWindowDpiMessagePtr func_ptr =
reinterpret_cast<EnableChildWindowDpiMessagePtr>(GetProcAddress(
GetModuleHandle(L"user32.dll"), "EnableChildWindowDpiMessage"));
if (func_ptr)
if (func_ptr) {
func_ptr(hwnd_, TRUE);
}
}
if (!initially_hidden) {
@@ -418,8 +432,9 @@ void RootWindowWin::RegisterRootClass(HINSTANCE hInstance,
HBRUSH background_brush) {
// Only register the class one time.
static bool class_registered = false;
if (class_registered)
if (class_registered) {
return;
}
class_registered = true;
WNDCLASSEX wcex;
@@ -516,8 +531,9 @@ LRESULT CALLBACK RootWindowWin::RootWndProc(HWND hWnd,
RootWindowWin* self = nullptr;
if (message != WM_NCCREATE) {
self = GetUserDataPtr<RootWindowWin*>(hWnd);
if (!self)
if (!self) {
return DefWindowProc(hWnd, message, wParam, lParam);
}
DCHECK_EQ(hWnd, self->hwnd_);
}
@@ -532,8 +548,9 @@ LRESULT CALLBACK RootWindowWin::RootWndProc(HWND hWnd,
// Callback for the main window
switch (message) {
case WM_COMMAND:
if (self->OnCommand(LOWORD(wParam)))
if (self->OnCommand(LOWORD(wParam))) {
return 0;
}
break;
case WM_GETOBJECT: {
@@ -543,8 +560,9 @@ LRESULT CALLBACK RootWindowWin::RootWndProc(HWND hWnd,
// Accessibility readers will send an OBJID_CLIENT message.
if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) {
if (self->GetBrowser() && self->GetBrowser()->GetHost())
if (self->GetBrowser() && self->GetBrowser()->GetHost()) {
self->GetBrowser()->GetHost()->SetAccessibilityState(STATE_ENABLED);
}
}
} break;
@@ -584,8 +602,9 @@ LRESULT CALLBACK RootWindowWin::RootWndProc(HWND hWnd,
break;
case WM_ERASEBKGND:
if (self->OnEraseBkgnd())
if (self->OnEraseBkgnd()) {
break;
}
// Don't erase the background.
return 0;
@@ -604,8 +623,9 @@ LRESULT CALLBACK RootWindowWin::RootWndProc(HWND hWnd,
break;
case WM_CLOSE:
if (self->OnClose())
if (self->OnClose()) {
return 0; // Cancel the close.
}
break;
case WM_NCHITTEST: {
@@ -659,25 +679,29 @@ void RootWindowWin::OnFocus() {
// Selecting "Close window" from the task bar menu may send a focus
// notification even though the window is currently disabled (e.g. while a
// modal JS dialog is displayed).
if (browser_window_ && ::IsWindowEnabled(hwnd_))
if (browser_window_ && ::IsWindowEnabled(hwnd_)) {
browser_window_->SetFocus(true);
}
}
void RootWindowWin::OnActivate(bool active) {
if (active)
if (active) {
delegate_->OnRootWindowActivated(this);
}
}
void RootWindowWin::OnSize(bool minimized) {
if (minimized) {
// Notify the browser window that it was hidden and do nothing further.
if (browser_window_)
if (browser_window_) {
browser_window_->Hide();
}
return;
}
if (browser_window_)
if (browser_window_) {
browser_window_->Show();
}
RECT rect;
GetClientRect(hwnd_, &rect);
@@ -718,8 +742,9 @@ void RootWindowWin::OnSize(bool minimized) {
// |browser_hwnd| may be nullptr if the browser has not yet been created.
HWND browser_hwnd = nullptr;
if (browser_window_)
if (browser_window_) {
browser_hwnd = browser_window_->GetWindowHandle();
}
// Resize all controls.
HDWP hdwp = BeginDeferWindowPos(browser_hwnd ? 6 : 5);
@@ -756,8 +781,9 @@ void RootWindowWin::OnMove() {
// Notify the browser of move events so that popup windows are displayed
// in the correct location and dismissed when the window moves.
CefRefPtr<CefBrowser> browser = GetBrowser();
if (browser)
if (browser) {
browser->GetHost()->NotifyMoveOrResizeStarted();
}
}
void RootWindowWin::OnDpiChanged(WPARAM wParam, LPARAM lParam) {
@@ -801,20 +827,24 @@ bool RootWindowWin::OnCommand(UINT id) {
OnFind();
return true;
case IDC_NAV_BACK: // Back button
if (CefRefPtr<CefBrowser> browser = GetBrowser())
if (CefRefPtr<CefBrowser> browser = GetBrowser()) {
browser->GoBack();
}
return true;
case IDC_NAV_FORWARD: // Forward button
if (CefRefPtr<CefBrowser> browser = GetBrowser())
if (CefRefPtr<CefBrowser> browser = GetBrowser()) {
browser->GoForward();
}
return true;
case IDC_NAV_RELOAD: // Reload button
if (CefRefPtr<CefBrowser> browser = GetBrowser())
if (CefRefPtr<CefBrowser> browser = GetBrowser()) {
browser->Reload();
}
return true;
case IDC_NAV_STOP: // Stop button
if (CefRefPtr<CefBrowser> browser = GetBrowser())
if (CefRefPtr<CefBrowser> browser = GetBrowser()) {
browser->StopLoad();
}
return true;
}
@@ -874,8 +904,9 @@ void RootWindowWin::OnFindEvent() {
browser->GetHost()->Find(find_what,
(find_state_.Flags & FR_DOWN) ? true : false,
match_case, find_next_);
if (!find_next_)
if (!find_next_) {
find_next_ = true;
}
}
}
@@ -1060,15 +1091,17 @@ void RootWindowWin::OnBrowserWindowDestroyed() {
void RootWindowWin::OnSetAddress(const std::string& url) {
REQUIRE_MAIN_THREAD();
if (edit_hwnd_)
if (edit_hwnd_) {
SetWindowText(edit_hwnd_, CefString(url).ToWString().c_str());
}
}
void RootWindowWin::OnSetTitle(const std::string& title) {
REQUIRE_MAIN_THREAD();
if (hwnd_)
if (hwnd_) {
SetWindowText(hwnd_, CefString(title).ToWString().c_str());
}
}
void RootWindowWin::OnSetFullscreen(bool fullscreen) {
@@ -1078,24 +1111,27 @@ void RootWindowWin::OnSetFullscreen(bool fullscreen) {
if (browser) {
std::unique_ptr<window_test::WindowTestRunnerWin> test_runner(
new window_test::WindowTestRunnerWin());
if (fullscreen)
if (fullscreen) {
test_runner->Maximize(browser);
else
} else {
test_runner->Restore(browser);
}
}
}
void RootWindowWin::OnAutoResize(const CefSize& new_size) {
REQUIRE_MAIN_THREAD();
if (!hwnd_)
if (!hwnd_) {
return;
}
int new_width = new_size.width;
// Make the window wide enough to drag by the top menu bar.
if (new_width < 200)
if (new_width < 200) {
new_width = 200;
}
const float device_scale_factor = GetWindowScaleFactor(hwnd_);
RECT rect = {0, 0, LogicalToDevice(new_width, device_scale_factor),
@@ -1249,8 +1285,9 @@ void RootWindowWin::OnSetDraggableRegions(
void RootWindowWin::NotifyDestroyedIfDone() {
// Notify once both the window and the browser have been destroyed.
if (window_destroyed_ && browser_destroyed_)
if (window_destroyed_ && browser_destroyed_) {
delegate_->OnRootWindowDestroyed(this);
}
}
// static

View File

@@ -93,11 +93,13 @@ class ServerHandler : public CefServerHandler {
CefURLParts url_parts;
CefParseURL(request->GetURL(), url_parts);
std::string path = CefString(&url_parts.path);
if (!path.empty() && path[0] == '/')
if (!path.empty() && path[0] == '/') {
path = path.substr(1);
}
if (path.empty())
if (path.empty()) {
path = kDefaultPath;
}
std::string mime_type;
const size_t sep = path.find_last_of(".");
@@ -108,8 +110,9 @@ class ServerHandler : public CefServerHandler {
// No extension. Assume html.
path += ".html";
}
if (mime_type.empty())
if (mime_type.empty()) {
mime_type = "text/html";
}
CefRefPtr<CefStreamReader> stream;
CefResponse::HeaderMap extra_headers;
@@ -189,8 +192,9 @@ class ServerHandler : public CefServerHandler {
size_t read;
do {
read = stream->Read(buffer, 1, sizeof(buffer));
if (read > 0)
if (read > 0) {
server->SendRawData(connection_id, buffer, read);
}
} while (!stream->Eof() && read != 0);
// Close the connection.
@@ -230,8 +234,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (url.find(kTestUrl) != 0)
if (url.find(kTestUrl) != 0) {
return false;
}
// Parse |request| as a JSON dictionary.
CefRefPtr<CefDictionaryValue> request_dict = ParseJSON(request);
@@ -240,8 +245,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
return true;
}
if (!VerifyKey(request_dict, kActionKey, VTYPE_STRING, callback))
if (!VerifyKey(request_dict, kActionKey, VTYPE_STRING, callback)) {
return true;
}
const std::string& action = request_dict->GetString(kActionKey);
if (action == "query") {
@@ -280,8 +286,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
return;
}
if (!VerifyKey(request_dict, kPortKey, VTYPE_INT, callback))
if (!VerifyKey(request_dict, kPortKey, VTYPE_INT, callback)) {
return;
}
const int port = request_dict->GetInt(kPortKey);
if (port < 8000 || port > 65535) {
@@ -350,8 +357,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Convert a JSON string to a dictionary value.
static CefRefPtr<CefDictionaryValue> ParseJSON(const CefString& string) {
CefRefPtr<CefValue> value = CefParseJSON(string, JSON_PARSER_RFC);
if (value.get() && value->GetType() == VTYPE_DICTIONARY)
if (value.get() && value->GetType() == VTYPE_DICTIONARY) {
return value->GetDictionary();
}
return nullptr;
}

View File

@@ -173,23 +173,26 @@ class PromptHandler : public CefMessageRouterBrowserSide::Handler {
CefRefPtr<Callback> callback) override {
// Parse |request| which takes the form "Prompt.[type]:[value]".
const std::string& request_str = request;
if (request_str.find(kPrompt) != 0)
if (request_str.find(kPrompt) != 0) {
return false;
}
std::string type = request_str.substr(sizeof(kPrompt) - 1);
size_t delim = type.find(':');
if (delim == std::string::npos)
if (delim == std::string::npos) {
return false;
}
const std::string& value = type.substr(delim + 1);
type = type.substr(0, delim);
// Canceling the prompt dialog returns a value of "null".
if (value != "null") {
if (type == kPromptFPS)
if (type == kPromptFPS) {
SetFPS(browser, atoi(value.c_str()));
else if (type == kPromptDSF)
} else if (type == kPromptDSF) {
SetDSF(browser, static_cast<float>(atof(value.c_str())));
}
}
// Nothing is done with the response.
@@ -290,8 +293,9 @@ void EndTracing(CefRefPtr<CefBrowser> browser) {
void RunDialog() {
static const char kDefaultFileName[] = "trace.txt";
std::string path = MainContext::Get()->GetDownloadPath(kDefaultFileName);
if (path.empty())
if (path.empty()) {
path = kDefaultFileName;
}
// Results in a call to OnFileDialogDismissed.
browser_->GetHost()->RunFileDialog(
@@ -341,8 +345,9 @@ void PrintToPDF(CefRefPtr<CefBrowser> browser) {
void RunDialog() {
static const char kDefaultFileName[] = "output.pdf";
std::string path = MainContext::Get()->GetDownloadPath(kDefaultFileName);
if (path.empty())
if (path.empty()) {
path = kDefaultFileName;
}
std::vector<CefString> accept_filters;
accept_filters.push_back(".pdf");
@@ -492,8 +497,9 @@ std::string RequestUrlFilter(const std::string& url) {
// Identify where the query or fragment component, if any, begins.
size_t suffix_pos = url.find('?');
if (suffix_pos == std::string::npos)
if (suffix_pos == std::string::npos) {
suffix_pos = url.find('#');
}
std::string url_base, url_suffix;
if (suffix_pos == std::string::npos) {
@@ -505,15 +511,17 @@ std::string RequestUrlFilter(const std::string& url) {
// Identify the last path component.
size_t path_pos = url_base.rfind('/');
if (path_pos == std::string::npos)
if (path_pos == std::string::npos) {
return url;
}
const std::string& path_component = url_base.substr(path_pos);
// Identify if a file extension is currently specified.
size_t ext_pos = path_component.rfind(".");
if (ext_pos != std::string::npos)
if (ext_pos != std::string::npos) {
return url;
}
// Rebuild the URL with a file extension.
return url_base + ".html" + url_suffix;
@@ -522,8 +530,9 @@ std::string RequestUrlFilter(const std::string& url) {
} // namespace
void RunTest(CefRefPtr<CefBrowser> browser, int id) {
if (!browser)
if (!browser) {
return;
}
switch (id) {
case ID_TESTS_GETSOURCE:
@@ -789,8 +798,9 @@ void Alert(CefRefPtr<CefBrowser> browser, const std::string& message) {
// Alerts originating from extension hosts should instead be displayed in
// the active browser.
browser = MainContext::Get()->GetRootWindowManager()->GetActiveBrowser();
if (!browser)
if (!browser) {
return;
}
}
// Escape special characters in the message.
@@ -807,8 +817,9 @@ bool IsTestURL(const std::string& url, const std::string& path) {
CefParseURL(url, parts);
const std::string& url_host = CefString(&parts.host);
if (url_host != kTestHost && url_host != kLocalHost)
if (url_host != kTestHost && url_host != kLocalHost) {
return false;
}
const std::string& url_path = CefString(&parts.path);
return url_path.find(path) == 0;

View File

@@ -16,7 +16,7 @@
// Implementation for the NSTextInputClient protocol used for enabling IME on
// mac when window rendering is disabled.
@interface CefTextInputClientOSRMac : NSObject<NSTextInputClient> {
@interface CefTextInputClientOSRMac : NSObject <NSTextInputClient> {
@private
// The range of current marked text inside the whole content of the DOM node

View File

@@ -89,8 +89,9 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
}
- (NSRange)selectedRange {
if (selectedRange_.location == NSNotFound || selectedRange_.length == 0)
if (selectedRange_.location == NSNotFound || selectedRange_.length == 0) {
return NSMakeRange(NSNotFound, 0);
}
return selectedRange_;
}
@@ -177,10 +178,11 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
// If we are handling a key down event then ImeFinishComposingText() will be
// called from the keyEvent: method.
if (!handlingKeyDown_)
if (!handlingKeyDown_) {
browser_->GetHost()->ImeFinishComposingText(false);
else
} else {
unmarkTextCalled_ = YES;
}
}
- (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)range
@@ -198,20 +200,23 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
NSUInteger location = theRange.location;
// If location is not specified fall back to the composition range start.
if (location == NSNotFound)
if (location == NSNotFound) {
location = markedRange_.location;
}
// Offset location by the composition range start if required.
if (location >= markedRange_.location)
if (location >= markedRange_.location) {
location -= markedRange_.location;
}
if (location < composition_bounds_.size()) {
const CefRect& rc = composition_bounds_[location];
rect = NSMakeRect(rc.x, rc.y, rc.width, rc.height);
}
if (actualRange)
if (actualRange) {
*actualRange = NSMakeRange(location, theRange.length);
}
return rect;
}
@@ -236,10 +241,11 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
// Convert into screen coordinates for return.
rect = [self screenRectFromViewRect:rect];
if (rect.origin.y >= rect.size.height)
if (rect.origin.y >= rect.size.height) {
rect.origin.y -= rect.size.height;
else
} else {
rect.origin.y = 0;
}
return rect;
}
@@ -284,8 +290,9 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
// Don't send a CHAR event for non-char keys like arrows, function keys and
// clear.
if (keyEvent.modifiers & (EVENTFLAG_IS_KEY_PAD)) {
if (keyEvent.native_key_code == 71)
if (keyEvent.native_key_code == 71) {
return;
}
}
keyEvent.type = KEYEVENT_CHAR;
@@ -313,10 +320,11 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
} else if (oldHasMarkedText_ && !hasMarkedText_ && !textInserted) {
// There was no marked text or inserted text. Complete or cancel the
// composition.
if (unmarkTextCalled_)
if (unmarkTextCalled_) {
browser_->GetHost()->ImeFinishComposingText(false);
else
} else {
browser_->GetHost()->ImeCancelComposition();
}
}
setMarkedTextReplacementRange_ = CefRange(UINT32_MAX, UINT32_MAX);
@@ -330,8 +338,9 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
}
- (void)cancelComposition {
if (!hasMarkedText_)
if (!hasMarkedText_) {
return;
}
// Cancel the ongoing composition. [NSInputManager markedTextAbandoned:]
// doesn't call any NSTextInput functions, such as setMarkedText or

View File

@@ -37,8 +37,9 @@ class RequestClient : public CefURLRequestClient {
void Detach() {
CEF_REQUIRE_UI_THREAD();
if (!callback_.is_null())
if (!callback_.is_null()) {
callback_.Reset();
}
}
void OnRequestComplete(CefRefPtr<CefURLRequest> request) override {
@@ -98,8 +99,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (!test_runner::IsTestURL(url, kTestUrlPath))
if (!test_runner::IsTestURL(url, kTestUrlPath)) {
return false;
}
const std::string& message_name = request;
if (message_name.find(kTestMessageName) == 0) {
@@ -160,10 +162,11 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
const std::string& download_data) {
CEF_REQUIRE_UI_THREAD();
if (error_code == ERR_NONE)
if (error_code == ERR_NONE) {
callback_->Success(download_data);
else
} else {
callback_->Failure(error_code, test_runner::GetErrorString(error_code));
}
callback_ = nullptr;
urlrequest_ = nullptr;

View File

@@ -33,8 +33,9 @@ char16 GetMnemonic(const std::u16string& title) {
do {
index = title.find('&', index);
if (index != std::u16string::npos) {
if (index + 1 != title.size() && title[index + 1] != '&')
if (index + 1 != title.size() && title[index + 1] != '&') {
return ToLower(title[index + 1]);
}
index++;
}
} while (index != std::u16string::npos);
@@ -67,8 +68,9 @@ CefRefPtr<CefMenuModel> ViewsMenuBar::CreateMenuModel(const CefString& label,
// Assign the new menu ID.
const int new_menu_id = id_next_++;
if (menu_id)
if (menu_id) {
*menu_id = new_menu_id;
}
// Create the new MenuModel.
CefRefPtr<CefMenuModel> model = CefMenuModel::CreateMenuModel(this);
@@ -91,24 +93,28 @@ CefRefPtr<CefMenuModel> ViewsMenuBar::CreateMenuModel(const CefString& label,
// Extract the mnemonic that triggers the menu, if any.
char16 mnemonic = GetMnemonic(label);
if (mnemonic != 0)
if (mnemonic != 0) {
mnemonics_.insert(std::make_pair(mnemonic, new_menu_id));
}
return model;
}
CefRefPtr<CefMenuModel> ViewsMenuBar::GetMenuModel(int menu_id) const {
if (HasMenuId(menu_id))
if (HasMenuId(menu_id)) {
return models_[menu_id - id_start_];
}
return nullptr;
}
void ViewsMenuBar::SetMenuFocusable(bool focusable) {
if (!panel_)
if (!panel_) {
return;
}
for (int id = id_start_; id < id_next_; ++id)
for (int id = id_start_; id < id_next_; ++id) {
panel_->GetViewForID(id)->SetFocusable(focusable);
}
if (focusable) {
// Give focus to the first MenuButton.
@@ -117,20 +123,24 @@ void ViewsMenuBar::SetMenuFocusable(bool focusable) {
}
bool ViewsMenuBar::OnKeyEvent(const CefKeyEvent& event) {
if (!panel_)
if (!panel_) {
return false;
}
if (event.type != KEYEVENT_RAWKEYDOWN)
if (event.type != KEYEVENT_RAWKEYDOWN) {
return false;
}
// Do not check mnemonics if the Alt or Ctrl modifiers are pressed. For
// example Ctrl+<T> is an accelerator, but <T> only is a mnemonic.
if (event.modifiers & (EVENTFLAG_ALT_DOWN | EVENTFLAG_CONTROL_DOWN))
if (event.modifiers & (EVENTFLAG_ALT_DOWN | EVENTFLAG_CONTROL_DOWN)) {
return false;
}
MnemonicMap::const_iterator it = mnemonics_.find(ToLower(event.character));
if (it == mnemonics_.end())
if (it == mnemonics_.end()) {
return false;
}
// Set status indicating that we navigated using the keyboard.
last_nav_with_keyboard_ = true;
@@ -189,30 +199,34 @@ void ViewsMenuBar::MouseOutsideMenu(CefRefPtr<CefMenuModel> menu_model,
// Convert the point from screen to window coordinates.
CefPoint window_point = screen_point;
if (!window->ConvertPointFromScreen(window_point))
if (!window->ConvertPointFromScreen(window_point)) {
return;
}
CefRect panel_bounds = panel_->GetBounds();
if (last_nav_with_keyboard_) {
// The user navigated last using the keyboard. Don't change menus using
// mouse movements until the mouse exits and re-enters the Panel.
if (panel_bounds.Contains(window_point))
if (panel_bounds.Contains(window_point)) {
return;
}
last_nav_with_keyboard_ = false;
}
// Check that the point is inside the Panel.
if (!panel_bounds.Contains(window_point))
if (!panel_bounds.Contains(window_point)) {
return;
}
const int active_menu_id = GetActiveMenuId();
// Determine which MenuButton is under the specified point.
for (int id = id_start_; id < id_next_; ++id) {
// Skip the currently active MenuButton.
if (id == active_menu_id)
if (id == active_menu_id) {
continue;
}
CefRefPtr<CefView> button = panel_->GetViewForID(id);
CefRect button_bounds = button->GetBounds();
@@ -241,13 +255,15 @@ void ViewsMenuBar::UnhandledCloseSubmenu(CefRefPtr<CefMenuModel> menu_model,
void ViewsMenuBar::MenuClosed(CefRefPtr<CefMenuModel> menu_model) {
// Reset |last_nav_with_keyboard_| status whenever the main menu closes.
if (!menu_model->IsSubMenu() && last_nav_with_keyboard_)
if (!menu_model->IsSubMenu() && last_nav_with_keyboard_) {
last_nav_with_keyboard_ = false;
}
}
void ViewsMenuBar::EnsureMenuPanel() {
if (panel_)
if (panel_) {
return;
}
panel_ = CefPanel::CreatePanel(nullptr);
views_style::ApplyTo(panel_);
@@ -263,8 +279,9 @@ int ViewsMenuBar::GetActiveMenuId() {
for (int id = id_start_; id < id_next_; ++id) {
CefRefPtr<CefButton> button = panel_->GetViewForID(id)->AsButton();
if (button->GetState() == CEF_BUTTON_STATE_PRESSED)
if (button->GetState() == CEF_BUTTON_STATE_PRESSED) {
return id;
}
}
return -1;
@@ -279,8 +296,9 @@ void ViewsMenuBar::TriggerNextMenu(int offset) {
// Compute the modulus to avoid negative values.
int next_menu_index = (active_menu_index + offset) % menu_count;
if (next_menu_index < 0)
if (next_menu_index < 0) {
next_menu_index += menu_count;
}
// Cancel the existing menu. MenuClosed may be called.
panel_->GetWindow()->CancelMenu();
@@ -295,8 +313,9 @@ void ViewsMenuBar::TriggerNextMenu(int offset) {
void ViewsMenuBar::TriggerMenuButton(CefRefPtr<CefView> button) {
CefRefPtr<CefMenuButton> menu_button =
button->AsButton()->AsLabelButton()->AsMenuButton();
if (menu_button->IsFocusable())
if (menu_button->IsFocusable()) {
menu_button->RequestFocus();
}
menu_button->TriggerMenu();
}

View File

@@ -147,10 +147,11 @@ void ViewsOverlayControls::OnButtonPressed(CefRefPtr<CefButton> button) {
window_->Minimize();
break;
case ViewsOverlayControls::Command::kMaximize:
if (window_->IsMaximized())
if (window_->IsMaximized()) {
window_->Restore();
else
} else {
window_->Maximize();
}
break;
case ViewsOverlayControls::Command::kClose:
window_->Close();
@@ -163,8 +164,9 @@ void ViewsOverlayControls::OnButtonPressed(CefRefPtr<CefButton> button) {
button->SetInkDropEnabled(false);
button->SetInkDropEnabled(true);
if (command == Command::kMaximize)
if (command == Command::kMaximize) {
MaybeUpdateMaximizeButton();
}
}
CefRefPtr<CefLabelButton> ViewsOverlayControls::CreateButton(Command command) {
@@ -178,8 +180,9 @@ CefRefPtr<CefLabelButton> ViewsOverlayControls::CreateButton(Command command) {
}
void ViewsOverlayControls::MaybeUpdateMaximizeButton() {
if (window_->IsMaximized() == window_maximized_)
if (window_->IsMaximized() == window_maximized_) {
return;
}
window_maximized_ = !window_maximized_;
auto max_button = panel_->GetChildViewAt(1);

View File

@@ -22,8 +22,9 @@ int GetShade(int component) {
void MaybeInitialize() {
static bool initialized = false;
if (initialized)
if (initialized) {
return;
}
g_background_color = MainContext::Get()->GetBackgroundColor();
if (g_background_color != 0) {
@@ -50,22 +51,25 @@ bool IsSet() {
}
void ApplyBackgroundTo(CefRefPtr<CefView> view) {
if (!IsSet())
if (!IsSet()) {
return;
}
view->SetBackgroundColor(g_background_color);
}
void ApplyTo(CefRefPtr<CefPanel> panel) {
if (!IsSet())
if (!IsSet()) {
return;
}
panel->SetBackgroundColor(g_background_color);
}
void ApplyTo(CefRefPtr<CefLabelButton> label_button) {
if (!IsSet())
if (!IsSet()) {
return;
}
// All text except disabled gets the same color.
label_button->SetEnabledTextColors(g_text_color);
@@ -76,16 +80,18 @@ void ApplyTo(CefRefPtr<CefLabelButton> label_button) {
}
void ApplyTo(CefRefPtr<CefTextfield> textfield) {
if (!IsSet())
if (!IsSet()) {
return;
}
textfield->SetBackgroundColor(g_background_color);
textfield->SetTextColor(g_text_color);
}
void ApplyTo(CefRefPtr<CefMenuModel> menu_model) {
if (!IsSet())
if (!IsSet()) {
return;
}
// All text except non-hovered accelerator gets the same color.
menu_model->SetColorAt(-1, CEF_MENU_COLOR_TEXT, g_text_color);
@@ -101,8 +107,9 @@ void ApplyTo(CefRefPtr<CefMenuModel> menu_model) {
// Recursively color sub-menus.
for (size_t i = 0; i < menu_model->GetCount(); ++i) {
if (menu_model->GetTypeAt(i) == MENUITEMTYPE_SUBMENU)
if (menu_model->GetTypeAt(i) == MENUITEMTYPE_SUBMENU) {
ApplyTo(menu_model->GetSubMenuAt(i));
}
}
}

View File

@@ -63,10 +63,12 @@ void MakeButtonsSameSize(const LabelButtons& buttons) {
// Determine the largest button size.
for (size_t i = 0U; i < buttons.size(); ++i) {
const CefSize& button_size = buttons[i]->GetPreferredSize();
if (size.width < button_size.width)
if (size.width < button_size.width) {
size.width = button_size.width;
if (size.height < button_size.height)
}
if (size.height < button_size.height) {
size.height = button_size.height;
}
}
for (size_t i = 0U; i < buttons.size(); ++i) {
@@ -134,8 +136,9 @@ CefRefPtr<ViewsWindow> ViewsWindow::Create(
void ViewsWindow::Show() {
CEF_REQUIRE_UI_THREAD();
if (window_)
if (window_) {
window_->Show();
}
if (browser_view_ && !window_->IsMinimized()) {
// Give keyboard focus to the BrowserView.
browser_view_->RequestFocus();
@@ -144,45 +147,52 @@ void ViewsWindow::Show() {
void ViewsWindow::Hide() {
CEF_REQUIRE_UI_THREAD();
if (window_)
if (window_) {
window_->Hide();
}
}
void ViewsWindow::Minimize() {
CEF_REQUIRE_UI_THREAD();
if (window_)
if (window_) {
window_->Minimize();
}
}
void ViewsWindow::Maximize() {
CEF_REQUIRE_UI_THREAD();
if (window_)
if (window_) {
window_->Maximize();
}
}
void ViewsWindow::SetBounds(const CefRect& bounds) {
CEF_REQUIRE_UI_THREAD();
if (window_)
if (window_) {
window_->SetBounds(bounds);
}
}
void ViewsWindow::SetBrowserSize(const CefSize& size,
bool has_position,
const CefPoint& position) {
CEF_REQUIRE_UI_THREAD();
if (browser_view_)
if (browser_view_) {
browser_view_->SetSize(size);
}
if (window_) {
window_->SizeToPreferredSize();
if (has_position)
if (has_position) {
window_->SetPosition(position);
}
}
}
void ViewsWindow::Close(bool force) {
CEF_REQUIRE_UI_THREAD();
if (!browser_view_)
if (!browser_view_) {
return;
}
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
if (browser) {
@@ -194,18 +204,21 @@ void ViewsWindow::Close(bool force) {
void ViewsWindow::SetAddress(const std::string& url) {
CEF_REQUIRE_UI_THREAD();
if (!window_)
if (!window_) {
return;
}
// |location_bar_| may instead be a Chrome toolbar.
if (location_bar_ && location_bar_->AsTextfield())
if (location_bar_ && location_bar_->AsTextfield()) {
location_bar_->AsTextfield()->SetText(url);
}
}
void ViewsWindow::SetTitle(const std::string& title) {
CEF_REQUIRE_UI_THREAD();
if (window_)
if (window_) {
window_->SetTitle(title);
}
}
void ViewsWindow::SetFavicon(CefRefPtr<CefImage> image) {
@@ -214,16 +227,18 @@ void ViewsWindow::SetFavicon(CefRefPtr<CefImage> image) {
// Window icons should be 16 DIP in size.
DCHECK_EQ(std::max(image->GetWidth(), image->GetHeight()), 16U);
if (window_)
if (window_) {
window_->SetWindowIcon(image);
}
}
void ViewsWindow::SetFullscreen(bool fullscreen) {
CEF_REQUIRE_UI_THREAD();
if (window_) {
// Hide the top controls while in full-screen mode.
if (with_controls_)
if (with_controls_) {
ShowTopControls(!fullscreen);
}
window_->SetFullscreen(fullscreen);
}
@@ -240,8 +255,9 @@ void ViewsWindow::SetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) {
CEF_REQUIRE_UI_THREAD();
if (!window_ || chrome_toolbar_type_ == CEF_CTT_NORMAL)
if (!window_ || chrome_toolbar_type_ == CEF_CTT_NORMAL) {
return;
}
if (with_controls_) {
EnableView(ID_BACK_BUTTON, canGoBack);
@@ -258,8 +274,9 @@ void ViewsWindow::SetDraggableRegions(
const std::vector<CefDraggableRegion>& regions) {
CEF_REQUIRE_UI_THREAD();
if (!window_ || !browser_view_)
if (!window_ || !browser_view_) {
return;
}
std::vector<CefDraggableRegion> window_regions;
@@ -285,8 +302,9 @@ void ViewsWindow::SetDraggableRegions(
void ViewsWindow::TakeFocus(bool next) {
CEF_REQUIRE_UI_THREAD();
if (!window_)
if (!window_) {
return;
}
if (chrome_toolbar_type_ == CEF_CTT_NORMAL) {
top_toolbar_->RequestFocus();
@@ -340,16 +358,18 @@ bool ViewsWindow::GetWindowRestorePreferences(
cef_show_state_t& show_state,
std::optional<CefRect>& dip_bounds) {
CEF_REQUIRE_UI_THREAD();
if (!window_)
if (!window_) {
return false;
}
show_state = CEF_SHOW_STATE_NORMAL;
if (window_->IsMinimized())
if (window_->IsMinimized()) {
show_state = CEF_SHOW_STATE_MINIMIZED;
else if (window_->IsMaximized())
} else if (window_->IsMaximized()) {
show_state = CEF_SHOW_STATE_MAXIMIZED;
else if (window_->IsFullscreen())
} else if (window_->IsFullscreen()) {
show_state = CEF_SHOW_STATE_FULLSCREEN;
}
if (show_state == CEF_SHOW_STATE_NORMAL) {
// Use the current visible bounds.
@@ -375,8 +395,9 @@ CefRefPtr<CefBrowserViewDelegate> ViewsWindow::GetDelegateForPopupBrowserView(
Delegate* popup_delegate = delegate_->GetDelegateForPopup(client);
// May be nullptr when using the default popup behavior.
if (!popup_delegate)
if (!popup_delegate) {
return nullptr;
}
// Should not be the same RootWindowViews that owns |this|.
DCHECK(popup_delegate != delegate_);
@@ -397,8 +418,9 @@ bool ViewsWindow::OnPopupBrowserViewCreated(
popup_browser_view->GetDelegate().get()));
// May be nullptr when using the default popup behavior.
if (!popup_window)
if (!popup_window) {
return false;
}
// Should not be the same ViewsWindow as |this|.
DCHECK(popup_window != this);
@@ -422,12 +444,14 @@ void ViewsWindow::OnButtonPressed(CefRefPtr<CefButton> button) {
CEF_REQUIRE_UI_THREAD();
DCHECK(with_controls_);
if (!browser_view_)
if (!browser_view_) {
return;
}
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
if (!browser)
if (!browser) {
return;
}
switch (button->GetID()) {
case ID_BACK_BUTTON:
@@ -519,8 +543,9 @@ bool ViewsWindow::OnKeyEvent(CefRefPtr<CefTextfield> textfield,
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
if (browser) {
const CefString& url = textfield->GetText();
if (!url.empty())
if (!url.empty()) {
browser->GetMainFrame()->LoadURL(url);
}
}
// We handled the event.
@@ -635,8 +660,9 @@ bool ViewsWindow::CanClose(CefRefPtr<CefWindow> window) {
// Allow the window to close if the browser says it's OK.
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
if (browser)
if (browser) {
return browser->GetHost()->TryCloseBrowser();
}
return true;
}
@@ -696,8 +722,9 @@ bool ViewsWindow::OnKeyEvent(CefRefPtr<CefWindow> window,
const CefKeyEvent& event) {
CEF_REQUIRE_UI_THREAD();
if (!window_)
if (!window_) {
return false;
}
if (delegate_->WithExtension() && event.type == KEYEVENT_RAWKEYDOWN &&
event.windows_key_code == VK_ESCAPE) {
@@ -706,8 +733,9 @@ bool ViewsWindow::OnKeyEvent(CefRefPtr<CefWindow> window,
return true;
}
if (!with_controls_)
if (!with_controls_) {
return false;
}
if (event.type == KEYEVENT_RAWKEYDOWN && event.windows_key_code == VK_MENU) {
// ALT key is pressed.
@@ -725,8 +753,9 @@ bool ViewsWindow::OnKeyEvent(CefRefPtr<CefWindow> window,
return true;
}
if (menu_has_focus_ && top_menu_bar_)
if (menu_has_focus_ && top_menu_bar_) {
return top_menu_bar_->OnKeyEvent(event);
}
return false;
}
@@ -734,8 +763,9 @@ bool ViewsWindow::OnKeyEvent(CefRefPtr<CefWindow> window,
CefSize ViewsWindow::GetMinimumSize(CefRefPtr<CefView> view) {
CEF_REQUIRE_UI_THREAD();
if (view->GetID() == ID_WINDOW)
if (view->GetID() == ID_WINDOW) {
return minimum_window_size_;
}
return CefSize();
}
@@ -754,8 +784,9 @@ void ViewsWindow::OnFocus(CefRefPtr<CefView> view) {
// When focus leaves the menu buttons make them unfocusable.
if (menu_has_focus_) {
if (top_menu_bar_) {
if (!top_menu_bar_->HasMenuId(view_id))
if (!top_menu_bar_->HasMenuId(view_id)) {
SetMenuFocusable(false);
}
} else if (view_id != ID_MENU_BUTTON) {
SetMenuFocusable(false);
}
@@ -774,8 +805,9 @@ void ViewsWindow::OnBlur(CefRefPtr<CefView> view) {
void ViewsWindow::OnWindowChanged(CefRefPtr<CefView> view, bool added) {
const int view_id = view->GetID();
if (view_id != ID_BROWSER_VIEW)
if (view_id != ID_BROWSER_VIEW) {
return;
}
if (added) {
if (with_controls_) {
@@ -802,8 +834,9 @@ void ViewsWindow::OnWindowChanged(CefRefPtr<CefView> view, bool added) {
void ViewsWindow::OnLayoutChanged(CefRefPtr<CefView> view,
const CefRect& new_bounds) {
const int view_id = view->GetID();
if (view_id != ID_BROWSER_VIEW)
if (view_id != ID_BROWSER_VIEW) {
return;
}
if (overlay_controls_) {
overlay_controls_->UpdateControls();
@@ -823,8 +856,9 @@ ViewsWindow::ViewsWindow(Delegate* delegate,
menu_has_focus_(false),
last_focused_view_(false) {
DCHECK(delegate_);
if (browser_view)
if (browser_view) {
SetBrowserView(browser_view);
}
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
@@ -959,8 +993,9 @@ void ViewsWindow::AddControls() {
// the CefWindow. This is a requirement to use Chrome toolbars.
CefRefPtr<CefPanel> top_menu_panel;
if (top_menu_bar_)
if (top_menu_bar_) {
top_menu_panel = top_menu_bar_->GetMenuPanel();
}
LabelButtons browse_buttons;
@@ -990,8 +1025,9 @@ void ViewsWindow::AddControls() {
top_panel->SetToBoxLayout(top_panel_layout_settings);
// Add the buttons and URL textfield to |top_panel|.
for (size_t i = 0U; i < browse_buttons.size(); ++i)
for (size_t i = 0U; i < browse_buttons.size(); ++i) {
top_panel->AddChildView(browse_buttons[i]);
}
top_panel->AddChildView(location_bar_);
UpdateExtensionControls();
@@ -1009,8 +1045,9 @@ void ViewsWindow::AddControls() {
// Add the top panel and browser view to |window|.
int top_index = 0;
if (top_menu_panel)
if (top_menu_panel) {
window_->AddChildViewAt(top_menu_panel, top_index++);
}
window_->AddChildViewAt(top_toolbar_, top_index);
// Lay out |window| so we can get the default button sizes.
@@ -1031,8 +1068,9 @@ void ViewsWindow::AddControls() {
// Minimum window height is the hight of the top toolbar plus some extra.
int min_height = top_toolbar_->GetBounds().height + 100;
if (top_menu_panel)
if (top_menu_panel) {
min_height += top_menu_panel->GetBounds().height;
}
minimum_window_size_ = CefSize(min_width, min_height);
}
@@ -1047,8 +1085,9 @@ void ViewsWindow::AddAccelerators() {
}
void ViewsWindow::SetMenuFocusable(bool focusable) {
if (!window_ || !with_controls_)
if (!window_ || !with_controls_) {
return;
}
if (top_menu_bar_) {
top_menu_bar_->SetMenuFocusable(focusable);
@@ -1065,19 +1104,22 @@ void ViewsWindow::SetMenuFocusable(bool focusable) {
}
void ViewsWindow::EnableView(int id, bool enable) {
if (!window_)
if (!window_) {
return;
}
// Special handling for |location_bar_| which may be an overlay (e.g. not a
// child of this view).
CefRefPtr<CefView> view =
id == ID_URL_TEXTFIELD ? location_bar_ : window_->GetViewForID(id);
if (view)
if (view) {
view->SetEnabled(enable);
}
}
void ViewsWindow::ShowTopControls(bool show) {
if (!window_ || !with_controls_)
if (!window_ || !with_controls_) {
return;
}
// Change the visibility of the top toolbar.
if (top_toolbar_->IsVisible() != show) {
@@ -1089,8 +1131,9 @@ void ViewsWindow::ShowTopControls(bool show) {
void ViewsWindow::UpdateExtensionControls() {
CEF_REQUIRE_UI_THREAD();
if (!window_ || !with_controls_)
if (!window_ || !with_controls_) {
return;
}
if (!extensions_panel_) {
extensions_panel_ = CefPanel::CreatePanel(nullptr);
@@ -1125,8 +1168,9 @@ void ViewsWindow::UpdateExtensionControls() {
}
CefRefPtr<CefView> parent_view = extensions_panel_->GetParentView();
if (parent_view)
if (parent_view) {
parent_view->InvalidateLayout();
}
}
void ViewsWindow::OnExtensionIconsLoaded(const ExtensionSet& extensions,
@@ -1146,8 +1190,9 @@ void ViewsWindow::OnExtensionIconsLoaded(const ExtensionSet& extensions,
ImageCache::ImageSet::const_iterator it2 = images.begin();
for (; it1 != extensions.end() && it2 != images.end(); ++it1, ++it2) {
CefRefPtr<CefImage> icon = *it2;
if (!icon)
if (!icon) {
icon = delegate_->GetImageCache()->GetCachedImage(kDefaultExtensionIcon);
}
extensions_.push_back(ExtensionInfo(*it1, icon));
}

View File

@@ -41,8 +41,9 @@ const char kMessageRestoreName[] = "WindowTest.Restore";
// Create the appropriate platform test runner object.
std::unique_ptr<WindowTestRunner> CreateWindowTestRunner() {
#if defined(OS_WIN) || defined(OS_LINUX)
if (MainContext::Get()->UseViews())
if (MainContext::Get()->UseViews()) {
return std::make_unique<WindowTestRunnerViews>();
}
#endif
#if defined(OS_WIN)
@@ -70,8 +71,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
CefRefPtr<Callback> callback) override {
// Only handle messages from the test URL.
const std::string& url = frame->GetURL();
if (!test_runner::IsTestURL(url, kTestUrlPath))
if (!test_runner::IsTestURL(url, kTestUrlPath)) {
return false;
}
const std::string& message_name = request;
if (message_name.find(kMessagePositionName) == 0) {
@@ -83,8 +85,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
int i;
while (ss >> i) {
vec.push_back(i);
if (ss.peek() == ',')
if (ss.peek() == ',') {
ss.ignore();
}
}
if (vec.size() == 4) {

View File

@@ -12,22 +12,28 @@ void WindowTestRunner::ModifyBounds(const CefRect& display, CefRect& window) {
window.x += display.x;
window.y += display.y;
if (window.x < display.x)
if (window.x < display.x) {
window.x = display.x;
if (window.y < display.y)
}
if (window.y < display.y) {
window.y = display.y;
if (window.width < 100)
}
if (window.width < 100) {
window.width = 100;
else if (window.width >= display.width)
} else if (window.width >= display.width) {
window.width = display.width;
if (window.height < 100)
}
if (window.height < 100) {
window.height = 100;
else if (window.height >= display.height)
} else if (window.height >= display.height) {
window.height = display.height;
if (window.x + window.width >= display.x + display.width)
}
if (window.x + window.width >= display.x + display.width) {
window.x = display.x + display.width - window.width;
if (window.y + window.height >= display.y + display.height)
}
if (window.y + window.height >= display.y + display.height) {
window.y = display.y + display.height - window.height;
}
}
} // namespace window_test

View File

@@ -21,8 +21,9 @@ GtkWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
RootWindow::GetForBrowser(browser->GetIdentifier());
if (root_window) {
GtkWindow* window = GTK_WINDOW(root_window->GetWindowHandle());
if (!window)
if (!window) {
LOG(ERROR) << "No GtkWindow for browser";
}
return window;
}
return nullptr;
@@ -43,15 +44,17 @@ void SetPosImpl(CefRefPtr<CefBrowser> browser,
ScopedGdkThreadsEnter scoped_gdk_threads;
GtkWindow* window = GetWindow(browser);
if (!window)
if (!window) {
return;
}
GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window));
// Make sure the window isn't minimized or maximized.
if (IsMaximized(window))
if (IsMaximized(window)) {
gtk_window_unmaximize(window);
else
} else {
gtk_window_present(window);
}
// Retrieve information about the display that contains the window.
GdkScreen* screen = gdk_screen_get_default();
@@ -73,12 +76,14 @@ void MinimizeImpl(CefRefPtr<CefBrowser> browser) {
ScopedGdkThreadsEnter scoped_gdk_threads;
GtkWindow* window = GetWindow(browser);
if (!window)
if (!window) {
return;
}
// Unmaximize the window before minimizing so restore behaves correctly.
if (IsMaximized(window))
if (IsMaximized(window)) {
gtk_window_unmaximize(window);
}
gtk_window_iconify(window);
}
@@ -88,8 +93,9 @@ void MaximizeImpl(CefRefPtr<CefBrowser> browser) {
ScopedGdkThreadsEnter scoped_gdk_threads;
GtkWindow* window = GetWindow(browser);
if (!window)
if (!window) {
return;
}
gtk_window_maximize(window);
}
@@ -98,12 +104,14 @@ void RestoreImpl(CefRefPtr<CefBrowser> browser) {
ScopedGdkThreadsEnter scoped_gdk_threads;
GtkWindow* window = GetWindow(browser);
if (!window)
if (!window) {
return;
if (IsMaximized(window))
}
if (IsMaximized(window)) {
gtk_window_unmaximize(window);
else
} else {
gtk_window_present(window);
}
}
} // namespace

View File

@@ -35,15 +35,17 @@ void WindowTestRunnerMac::SetPos(CefRefPtr<CefBrowser> browser,
NSWindow* window = GetWindow(browser);
// Make sure the window isn't minimized or maximized.
if ([window isMiniaturized])
if ([window isMiniaturized]) {
[window deminiaturize:nil];
else if ([window isZoomed])
} else if ([window isZoomed]) {
[window performZoom:nil];
}
// Retrieve information for the display that contains the window.
NSScreen* screen = [window screen];
if (screen == nil)
if (screen == nil) {
screen = [NSScreen mainScreen];
}
NSRect frame = [screen frame];
NSRect visibleFrame = [screen visibleFrame];
@@ -82,10 +84,11 @@ void WindowTestRunnerMac::Restore(CefRefPtr<CefBrowser> browser) {
REQUIRE_MAIN_THREAD();
NSWindow* window = GetWindow(browser);
if ([window isMiniaturized])
if ([window isMiniaturized]) {
[window deminiaturize:nil];
else if ([window isZoomed])
} else if ([window isZoomed]) {
[window performZoom:nil];
}
}
} // namespace window_test

View File

@@ -21,10 +21,11 @@ void Toggle(HWND root_hwnd, UINT nCmdShow) {
WINDOWPLACEMENT placement;
::GetWindowPlacement(root_hwnd, &placement);
if (placement.showCmd == nCmdShow)
if (placement.showCmd == nCmdShow) {
::ShowWindow(root_hwnd, SW_RESTORE);
else
} else {
::ShowWindow(root_hwnd, nCmdShow);
}
}
void SetPosImpl(CefRefPtr<CefBrowser> browser,
@@ -33,8 +34,9 @@ void SetPosImpl(CefRefPtr<CefBrowser> browser,
int width,
int height) {
HWND root_hwnd = GetRootHwnd(browser);
if (!root_hwnd)
if (!root_hwnd) {
return;
}
// Retrieve current window placement information.
WINDOWPLACEMENT placement;
@@ -73,22 +75,25 @@ void SetPosImpl(CefRefPtr<CefBrowser> browser,
void MinimizeImpl(CefRefPtr<CefBrowser> browser) {
HWND root_hwnd = GetRootHwnd(browser);
if (!root_hwnd)
if (!root_hwnd) {
return;
}
Toggle(root_hwnd, SW_MINIMIZE);
}
void MaximizeImpl(CefRefPtr<CefBrowser> browser) {
HWND root_hwnd = GetRootHwnd(browser);
if (!root_hwnd)
if (!root_hwnd) {
return;
}
Toggle(root_hwnd, SW_MAXIMIZE);
}
void RestoreImpl(CefRefPtr<CefBrowser> browser) {
HWND root_hwnd = GetRootHwnd(browser);
if (!root_hwnd)
if (!root_hwnd) {
return;
}
::ShowWindow(root_hwnd, SW_RESTORE);
}