1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/page_transition_types.h"
7 #include "base/logging.h"
11 bool PageTransitionCoreTypeIs(PageTransition lhs
,
13 // Expect the rhs to be a compile time constant without qualifiers.
14 DCHECK_EQ(PageTransitionGetQualifier(rhs
), 0);
15 DCHECK(PageTransitionIsValidType(rhs
));
16 return PageTransitionStripQualifier(lhs
) == PageTransitionStripQualifier(rhs
);
19 PageTransition
PageTransitionStripQualifier(PageTransition type
) {
20 return static_cast<PageTransition
>(type
& ~PAGE_TRANSITION_QUALIFIER_MASK
);
23 bool PageTransitionIsValidType(int32 type
) {
24 PageTransition t
= PageTransitionStripQualifier(
25 static_cast<PageTransition
>(type
));
26 return (t
<= PAGE_TRANSITION_LAST_CORE
);
29 PageTransition
PageTransitionFromInt(int32 type
) {
30 if (!PageTransitionIsValidType(type
)) {
31 NOTREACHED() << "Invalid transition type " << type
;
33 // Return a safe default so we don't have corrupt data in release mode.
34 return PAGE_TRANSITION_LINK
;
36 return static_cast<PageTransition
>(type
);
39 bool PageTransitionIsMainFrame(PageTransition type
) {
40 int32 t
= PageTransitionStripQualifier(type
);
41 return (t
!= PAGE_TRANSITION_AUTO_SUBFRAME
&&
42 t
!= PAGE_TRANSITION_MANUAL_SUBFRAME
);
45 bool PageTransitionIsRedirect(PageTransition type
) {
46 return (type
& PAGE_TRANSITION_IS_REDIRECT_MASK
) != 0;
49 bool PageTransitionIsNewNavigation(PageTransition type
) {
50 return (type
& PAGE_TRANSITION_FORWARD_BACK
) == 0 &&
51 !PageTransitionCoreTypeIs(type
, PAGE_TRANSITION_RELOAD
);
54 int32
PageTransitionGetQualifier(PageTransition type
) {
55 return type
& PAGE_TRANSITION_QUALIFIER_MASK
;
58 bool PageTransitionIsWebTriggerable(PageTransition type
) {
59 int32 t
= PageTransitionStripQualifier(type
);
61 case PAGE_TRANSITION_LINK
:
62 case PAGE_TRANSITION_AUTO_SUBFRAME
:
63 case PAGE_TRANSITION_MANUAL_SUBFRAME
:
64 case PAGE_TRANSITION_FORM_SUBMIT
:
70 const char* PageTransitionGetCoreTransitionString(PageTransition type
) {
71 int32 t
= PageTransitionStripQualifier(type
);
73 case PAGE_TRANSITION_LINK
: return "link";
74 case PAGE_TRANSITION_TYPED
: return "typed";
75 case PAGE_TRANSITION_AUTO_BOOKMARK
: return "auto_bookmark";
76 case PAGE_TRANSITION_AUTO_SUBFRAME
: return "auto_subframe";
77 case PAGE_TRANSITION_MANUAL_SUBFRAME
: return "manual_subframe";
78 case PAGE_TRANSITION_GENERATED
: return "generated";
79 case PAGE_TRANSITION_AUTO_TOPLEVEL
: return "auto_toplevel";
80 case PAGE_TRANSITION_FORM_SUBMIT
: return "form_submit";
81 case PAGE_TRANSITION_RELOAD
: return "reload";
82 case PAGE_TRANSITION_KEYWORD
: return "keyword";
83 case PAGE_TRANSITION_KEYWORD_GENERATED
: return "keyword_generated";